-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathUser.java
More file actions
123 lines (91 loc) · 2.88 KB
/
User.java
File metadata and controls
123 lines (91 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.example.demo.model;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.validator.constraints.Length;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
@Entity
@Data
@Table(name = "users")
public class User implements UserDetails {
@SequenceGenerator(
name = "users_sequence",
sequenceName = "users_sequence",
allocationSize = 1
)
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "users_sequence"
)
private Long id;
@NotNull(message = "First Name cannot be empty")
@Column(name = "first_name")
private String firstName;
@NotNull(message = "Last Name cannot be empty")
@Column(name = "last_name")
private String lastName;
@NotNull(message = "Email cannot be empty")
@Email(message = "Please enter a valid email address")
@Column(name = "email", unique = true)
private String email;
@NotNull(message = "Password cannot be empty")
@Length(min = 7, message = "Password should be at least 7 characters long")
@Column(name = "password")
private String password;
@Column(name = "mobile", unique = true)
@Length(min = 10, message = "Password should be at least 10 number long")
private String mobile;
@CreationTimestamp
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;
@UpdateTimestamp
@Column(name = "updated_at")
private LocalDateTime updatedAt;
@Enumerated(EnumType.STRING)
private Role role;
@Column(name = "locked")
private Boolean locked = false;
@Column(name = "enabled")
private Boolean enabled = true;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.name());
return Collections.singletonList(authority);
}
@Override
public String getPassword() {
return password;
}
public void setPassword(String password){
this.password = password;
}
@Override
public String getUsername() {
return email;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return !locked;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return enabled;
}
}