backend/buisnesslogic/src/main/java/com/plannaplan/entities/User.java

101 lines
2.3 KiB
Java
Raw Normal View History

2020-07-25 10:38:19 +02:00
package com.plannaplan.entities;
2020-11-07 16:30:25 +01:00
import java.sql.Timestamp;
import java.util.concurrent.TimeUnit;
2020-07-25 10:38:19 +02:00
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.plannaplan.types.UserRoles;
2020-09-25 16:43:24 +02:00
/**
* Entity of User grouping of state ssociated about id,name,surname,email,role,token,tokenCreatedDate
*/
2020-07-25 10:38:19 +02:00
@Entity
public class User {
2020-11-07 16:30:25 +01:00
private static final float TOKEN_EXPIRE_MINUTES = 15;
2020-07-25 10:38:19 +02:00
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String surname;
private String email;
2020-07-25 10:38:19 +02:00
private UserRoles role;
private String token;
2020-11-07 16:30:25 +01:00
private Timestamp tokenUsageDate;
2020-07-25 10:38:19 +02:00
public User() {
}
2020-09-25 16:43:24 +02:00
public User(String name, String surname, String mail, UserRoles role) {
this.name = name;
this.surname = surname;
this.email = mail;
this.role = role;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
2020-11-07 16:30:25 +01:00
public Timestamp getTokenUsageDate() {
return tokenUsageDate;
}
public String getToken() {
return token;
}
public void setToken(String token) {
2020-11-07 16:30:25 +01:00
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
this.token = token;
}
2020-07-25 10:38:19 +02:00
public String getName() {
return name;
}
public UserRoles getRole() {
return role;
}
public void setRole(UserRoles role) {
this.role = role;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setName(String name) {
this.name = name;
}
2020-09-30 17:46:04 +02:00
public Long getId() {
return this.id;
}
2020-11-07 16:30:25 +01:00
public boolean isCredentialsNonExpired() {
final long diffInMilliseconds = Math
.abs(this.tokenUsageDate.getTime() - new Timestamp(System.currentTimeMillis()).getTime());
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
if (minutes > TOKEN_EXPIRE_MINUTES) {
return false;
}
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
return true;
}
2020-07-25 10:38:19 +02:00
}