86 lines
2.2 KiB
Java
86 lines
2.2 KiB
Java
package zw.qantra.tm.domain.models;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import jakarta.persistence.*;
|
|
import lombok.Data;
|
|
import lombok.EqualsAndHashCode;
|
|
import org.hibernate.annotations.SQLRestriction;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import java.util.Collection;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
@Entity
|
|
@Table(name = "users", indexes = {
|
|
@Index(name = "idx_user_phone", columnList = "phone"),
|
|
})
|
|
@Data
|
|
@EqualsAndHashCode(callSuper = true)
|
|
@SQLRestriction("deleted = false")
|
|
public class User extends BaseEntity implements UserDetails {
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String username;
|
|
|
|
@Column(nullable = false)
|
|
private String password;
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String email;
|
|
private String phone;
|
|
private String erpCustomerRef;
|
|
private String photoUrl;
|
|
private Long workflowId;
|
|
|
|
@Column(name = "first_name")
|
|
private String firstName;
|
|
|
|
@Column(name = "last_name")
|
|
private String lastName;
|
|
|
|
@Column(name = "is_enabled")
|
|
private boolean enabled = true;
|
|
|
|
@Column(name = "is_account_non_expired")
|
|
private boolean accountNonExpired = true;
|
|
|
|
@Column(name = "is_account_non_locked")
|
|
private boolean accountNonLocked = true;
|
|
|
|
@Column(name = "is_credentials_non_expired")
|
|
private boolean credentialsNonExpired = true;
|
|
|
|
@JsonIgnore
|
|
@ManyToMany(mappedBy = "users", fetch = FetchType.LAZY)
|
|
private Set<Workspace> workspaces = new HashSet<>();
|
|
|
|
@Override
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
return List.of(new SimpleGrantedAuthority("ROLE_USER"));
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonExpired() {
|
|
return accountNonExpired;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonLocked() {
|
|
return accountNonLocked;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCredentialsNonExpired() {
|
|
return credentialsNonExpired;
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled() {
|
|
return enabled;
|
|
}
|
|
}
|