UserAuth
package com.example.puyuan_lun.AccountFountion.UserAuth;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "user_auth")
public class UserAuth implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 255)
private String account;
@Column(nullable = false, unique = true, length = 255)
private String email;
@Column(nullable = false, unique = true, length = 255)
private String phone;
@Column(nullable = false, length = 255)
private String password;
@Column(length = 100)
private String fbId;
@Column(length = 50)
private String code;
@Column(nullable = false, columnDefinition = "TINYINT(1) default 0")
private Boolean verified;
@Column(nullable = false, columnDefinition = "TINYINT(1) default 0")
private Boolean privacyPolicy;
@Column(nullable = false, columnDefinition = "TINYINT(1) default 0")
private Boolean mustChangePassword;
@Column(length = 100)
private String fcmId;
private Integer loginTimes;
private Data createdAt;
private Data updatedAt;
@Enumerated(EnumType.STRING)
private Role role;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return List.of(new SimpleGrantedAuthority(role.name()));
}
@Override
public String getPassword() {
return password;
}
@Override
public String getUsername() {
return email;
}
@Override
public boolean isAccountNonExpired() {
return UserDetails.super.isAccountNonExpired();
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}