1 | package finki.diplomska.tripplanner.models;
|
---|
2 |
|
---|
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
|
---|
4 | import lombok.AllArgsConstructor;
|
---|
5 | import lombok.Getter;
|
---|
6 | import lombok.Setter;
|
---|
7 | import org.springframework.security.core.GrantedAuthority;
|
---|
8 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
9 |
|
---|
10 | import javax.persistence.*;
|
---|
11 | import javax.validation.constraints.Email;
|
---|
12 | import javax.validation.constraints.NotBlank;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.Date;
|
---|
15 |
|
---|
16 | @Entity
|
---|
17 | @Table(name = "users")
|
---|
18 | @AllArgsConstructor
|
---|
19 | @Getter
|
---|
20 | @Setter
|
---|
21 | public class User implements UserDetails {
|
---|
22 |
|
---|
23 | @Id
|
---|
24 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
25 | private Long id;
|
---|
26 |
|
---|
27 | @Email(message = "Username needs to be an email")
|
---|
28 | @NotBlank(message = "username is required")
|
---|
29 | @Column(unique = true)
|
---|
30 | private String username;
|
---|
31 | @NotBlank(message = "Please enter your full name")
|
---|
32 | private String fullName;
|
---|
33 | @NotBlank(message = "Password field is required")
|
---|
34 | private String password;
|
---|
35 | @Transient
|
---|
36 | private String confirmPassword;
|
---|
37 | private Date create_At;
|
---|
38 | private Date update_At;
|
---|
39 |
|
---|
40 | //OneToMany with Project
|
---|
41 |
|
---|
42 | public User() {
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | @PrePersist
|
---|
47 | protected void onCreate(){
|
---|
48 | this.create_At = new Date();
|
---|
49 | }
|
---|
50 | @PreUpdate
|
---|
51 | protected void onUpdate(){
|
---|
52 | this.update_At = new Date();
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | @JsonIgnore
|
---|
57 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
58 | return null;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | @JsonIgnore
|
---|
63 | public boolean isAccountNonExpired() {
|
---|
64 | return true;
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | @JsonIgnore
|
---|
69 | public boolean isAccountNonLocked() {
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | @JsonIgnore
|
---|
75 | public boolean isCredentialsNonExpired() {
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | @JsonIgnore
|
---|
81 | public boolean isEnabled() {
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 | }
|
---|