1 | package com.example.autopartz.model;
|
---|
2 |
|
---|
3 | import lombok.Getter;
|
---|
4 | import lombok.RequiredArgsConstructor;
|
---|
5 | import lombok.Setter;
|
---|
6 | import lombok.ToString;
|
---|
7 | import org.hibernate.Hibernate;
|
---|
8 | import org.springframework.security.core.GrantedAuthority;
|
---|
9 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
10 |
|
---|
11 | import javax.persistence.*;
|
---|
12 | import java.time.LocalDateTime;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.Collections;
|
---|
15 | import java.util.Objects;
|
---|
16 |
|
---|
17 | @Getter
|
---|
18 | @Setter
|
---|
19 | @ToString
|
---|
20 | @RequiredArgsConstructor
|
---|
21 | @Entity
|
---|
22 | @Table(name = "users_table")
|
---|
23 | @Inheritance(strategy = InheritanceType.JOINED)
|
---|
24 | public 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 | }
|
---|