backend/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java

68 lines
1.8 KiB
Java
Raw Normal View History

2020-02-27 16:31:28 +00:00
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.Date;
2020-05-24 10:18:28 +00:00
import java.util.Objects;
2020-02-27 16:31:28 +00:00
import java.util.UUID;
2020-05-18 15:58:38 +00:00
import javax.persistence.*;
2020-05-12 14:57:49 +00:00
import lombok.Data;
2020-05-23 21:23:24 +00:00
import lombok.NonNull;
2020-02-27 16:31:28 +00:00
2020-05-12 14:57:49 +00:00
@Data
2020-02-27 16:31:28 +00:00
@Entity
2020-05-27 08:34:48 +00:00
public final class ConfirmationToken {
2020-02-27 16:31:28 +00:00
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@Column(name = "confirmation_token", unique = true)
2020-05-10 10:39:18 +00:00
private String confirmToken;
2020-02-27 16:31:28 +00:00
2020-05-21 20:03:38 +00:00
public Date getCreatedDate() {
return new Date(createdDate.getTime());
}
public void setCreatedDate(Date createdDate) {
this.createdDate = new Date(createdDate.getTime());
}
2020-02-27 16:31:28 +00:00
@Temporal(TemporalType.TIMESTAMP)
2020-05-23 21:23:24 +00:00
@NonNull
2020-02-27 16:31:28 +00:00
private Date createdDate;
@OneToOne(targetEntity = User.class, fetch = FetchType.EAGER)
@JoinColumn(nullable = false, name = "user_id")
private User user;
@Column(nullable = false)
private boolean resetPassword;
2020-02-27 16:31:28 +00:00
public ConfirmationToken(User user) {
this.user = user;
createdDate = new Date();
2020-05-10 10:39:18 +00:00
confirmToken = UUID.randomUUID().toString();
resetPassword = false;
2020-02-27 16:31:28 +00:00
}
2020-05-24 10:18:28 +00:00
2020-05-26 22:01:55 +00:00
public ConfirmationToken() {
this((User) null);
}
2020-05-24 10:18:28 +00:00
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfirmationToken that = (ConfirmationToken) o;
return resetPassword == that.resetPassword
&& confirmToken.equals(that.confirmToken)
&& createdDate.equals(that.createdDate)
&& Objects.equals(user, that.user);
}
@Override
public int hashCode() {
2020-05-27 08:34:48 +00:00
return Objects.hash(confirmToken, createdDate, user, resetPassword);
2020-05-24 10:18:28 +00:00
}
2020-02-27 16:31:28 +00:00
}