97 lines
2.2 KiB
Java
Executable File
97 lines
2.2 KiB
Java
Executable File
package com.plannaplan.entities;
|
|
|
|
import java.sql.Timestamp;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.GeneratedValue;
|
|
import javax.persistence.GenerationType;
|
|
import javax.persistence.Id;
|
|
|
|
import com.plannaplan.types.UserRoles;
|
|
|
|
@Entity
|
|
public class User {
|
|
private static final float TOKEN_EXPIRE_MINUTES = 15;
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
private Long id;
|
|
private String name;
|
|
private String surname;
|
|
private String email;
|
|
private UserRoles role;
|
|
private String token;
|
|
private Timestamp tokenUsageDate;
|
|
|
|
public User() {
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public Timestamp getTokenUsageDate() {
|
|
return tokenUsageDate;
|
|
}
|
|
|
|
public String getToken() {
|
|
return token;
|
|
}
|
|
|
|
public void setToken(String token) {
|
|
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
|
this.token = token;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public Long getId() {
|
|
return this.id;
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |