package ee.esutoniagodesu.domain.ac.table; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.io.Serializable; import java.time.ZonedDateTime; @Entity @Table(schema = "ac", name = "user_account_form") public class UserAccountForm implements Serializable { public static final int PASSWORD_MIN_LENGTH = 5; public static final int PASSWORD_MAX_LENGTH = 100; @JsonIgnore @MapsId @OneToOne @JoinColumn(name = "user_id") private User user; @JsonIgnore @Id @Column(name = "user_id") private Integer userId; @NotNull @Pattern(regexp = "^[a-z0-9]*$") @Size(min = 1, max = 50) @Column(length = 50, unique = true, nullable = false) private String login; @JsonIgnore @NotNull @Size(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH) @Column(length = 100) private String password; @JsonIgnore @Size(max = 20) @Column(name = "reset_key", length = 20) private String resetKey; @JsonIgnore @Column(name = "reset_date", nullable = true) private ZonedDateTime resetDate = null; public UserAccountForm() { } public UserAccountForm(String login, String password) { this.login = login; this.password = password; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } @JsonIgnore public String getPassword() { return password; } @JsonProperty public void setPassword(String password) { this.password = password; } public String getResetKey() { return resetKey; } public void setResetKey(String resetKey) { this.resetKey = resetKey; } public ZonedDateTime getResetDate() { return resetDate; } public void setResetDate(ZonedDateTime resetDate) { this.resetDate = resetDate; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; UserAccountForm that = (UserAccountForm) o; if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false; return !(login != null ? !login.equals(that.login) : that.login != null); } @Override public int hashCode() { int result = userId != null ? userId.hashCode() : 0; result = 31 * result + (login != null ? login.hashCode() : 0); return result; } @Override public String toString() { return "UserAccountForm{" + "userId=" + userId + ", login='" + login + '\'' + ", password='" + (password != null ? "[SECRET]" : null) + '\'' + ", resetKey='" + resetKey + '\'' + ", resetDate=" + resetDate + '}'; } }