source: src/main/java/com/example/autopartz/model/User.java

main
Last change on this file was 676144b, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 23 months ago

Added admin view of pending roles and approve functionality

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package com.example.autopartz.model;
2
3import lombok.Getter;
4import lombok.RequiredArgsConstructor;
5import lombok.Setter;
6import lombok.ToString;
7import org.hibernate.Hibernate;
8import org.springframework.security.core.GrantedAuthority;
9import org.springframework.security.core.userdetails.UserDetails;
10
11import javax.persistence.*;
12import java.time.LocalDateTime;
13import java.util.Collection;
14import java.util.Collections;
15import java.util.Objects;
16
17@Getter
18@Setter
19@ToString
20@RequiredArgsConstructor
21@Entity
22@Table(name = "users_table")
23@Inheritance(strategy = InheritanceType.JOINED)
24public class User implements UserDetails {
25 @Id
26 @GeneratedValue(strategy = GenerationType.IDENTITY)
27 @Column(name = "ID_user")
28 Integer id;
29 String username;
30 String email;
31 @Column(name = "name_user")
32 String name;
33 @Column(name = "password_user")
34 String password;
35 LocalDateTime user_created_on;
36 String phone_number;
37 @ManyToOne
38 @JoinColumn(name = "id_administrator")
39 Administrator administrator;
40
41 public User(String username, String name, String email, String password, String number) {
42 this.username = username;
43 this.name = name;
44 this.email = email;
45 this.password = password;
46 this.phone_number = number;
47 this.user_created_on = LocalDateTime.now();
48 }
49
50 @Override
51 public boolean equals(Object o) {
52 if (this == o) return true;
53 if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
54 User user = (User) o;
55 return id != null && Objects.equals(id, user.id);
56 }
57
58 @Override
59 public int hashCode() {
60 return getClass().hashCode();
61 }
62
63
64 @Override
65 public Collection<? extends GrantedAuthority> getAuthorities() {
66 return Collections.singletonList(Role.ROLE_USER);
67 }
68
69 @Override
70 public boolean isAccountNonExpired() {
71 return true;
72 }
73
74 @Override
75 public boolean isAccountNonLocked() {
76 return true;
77 }
78
79 @Override
80 public boolean isCredentialsNonExpired() {
81 return true;
82 }
83
84 @Override
85 public boolean isEnabled() {
86 return true;
87 }
88}
Note: See TracBrowser for help on using the repository browser.