2026-01-16 20:20:14 +07:00
|
|
|
package ru.soune.nocopy.entity.user;
|
2025-11-24 10:26:19 +07:00
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
import jakarta.validation.constraints.Size;
|
2025-11-24 10:26:19 +07:00
|
|
|
import lombok.*;
|
2026-02-17 20:17:34 +07:00
|
|
|
import org.hibernate.annotations.ColumnDefault;
|
2025-11-24 12:29:32 +07:00
|
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
|
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
2026-01-29 19:24:36 +07:00
|
|
|
import ru.soune.nocopy.entity.company.Company;
|
2026-01-30 12:52:16 +07:00
|
|
|
import ru.soune.nocopy.entity.tarif.TariffInfo;
|
|
|
|
|
import ru.soune.nocopy.entity.tarif.TariffStatus;
|
2025-11-24 12:29:32 +07:00
|
|
|
|
2025-11-27 03:05:07 +07:00
|
|
|
import java.time.LocalDate;
|
2025-11-24 12:29:32 +07:00
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2025-11-24 10:26:19 +07:00
|
|
|
|
|
|
|
|
@Entity
|
2025-11-24 12:29:32 +07:00
|
|
|
@Table(name = "users")
|
2025-11-26 15:49:51 +07:00
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@ToString
|
|
|
|
|
@EntityListeners(AuditingEntityListener.class)
|
2025-11-24 10:26:19 +07:00
|
|
|
public class User {
|
2025-11-24 12:29:32 +07:00
|
|
|
|
2025-11-24 10:26:19 +07:00
|
|
|
@Id
|
2025-11-24 12:29:32 +07:00
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
2025-11-27 03:05:07 +07:00
|
|
|
private Long Id;
|
2025-11-24 10:26:19 +07:00
|
|
|
|
2025-11-27 03:05:07 +07:00
|
|
|
@Column(name = "full_name", nullable = false)
|
|
|
|
|
private String fullName;
|
2025-11-24 12:29:32 +07:00
|
|
|
|
|
|
|
|
@Size(max = 1024)
|
|
|
|
|
@Column(name = "email", nullable = false, length = 1024, unique = true)
|
|
|
|
|
private String email;
|
|
|
|
|
|
2026-01-19 19:26:59 +07:00
|
|
|
@Column(name = "email_verified")
|
|
|
|
|
private boolean emailVerified = false;
|
2026-01-16 20:20:14 +07:00
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
@Column(nullable = false)
|
2025-11-27 03:05:07 +07:00
|
|
|
@Size(min = 6)
|
2025-11-24 12:29:32 +07:00
|
|
|
@JsonIgnore
|
|
|
|
|
private String password;
|
|
|
|
|
|
2025-11-27 03:05:07 +07:00
|
|
|
@Size(min = 11, max = 14)
|
2025-12-16 16:43:20 +07:00
|
|
|
@Column(unique = true)
|
2025-11-27 03:05:07 +07:00
|
|
|
private String phone;
|
|
|
|
|
|
2025-11-26 15:49:51 +07:00
|
|
|
@Enumerated(EnumType.STRING)
|
|
|
|
|
@Column(name = "subscription_type", nullable = false, length = 20)
|
2025-11-27 03:05:07 +07:00
|
|
|
private SubscriptionType subscriptionType = SubscriptionType.DEMO;
|
|
|
|
|
|
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
|
|
|
@Column(name = "gender")
|
|
|
|
|
private GenderType genderType = GenderType.MALE;
|
|
|
|
|
|
|
|
|
|
@Column(name = "birthday")
|
|
|
|
|
private LocalDate birthday;
|
2025-11-24 12:29:32 +07:00
|
|
|
|
|
|
|
|
@CreatedDate
|
|
|
|
|
@Column(name = "created_at", updatable = false, nullable = false)
|
|
|
|
|
private LocalDateTime createdAt;
|
|
|
|
|
|
2025-11-26 15:49:51 +07:00
|
|
|
@Column(name = "last_login_at")
|
|
|
|
|
private LocalDateTime lastLoginAt;
|
|
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
@Column(name = "is_active")
|
2026-01-20 15:12:24 +07:00
|
|
|
private boolean isActive = false;
|
2025-11-24 10:26:19 +07:00
|
|
|
|
2025-11-26 15:49:51 +07:00
|
|
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
@ToString.Exclude
|
|
|
|
|
private List<AuthToken> tokens = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
@ToString.Exclude
|
|
|
|
|
private List<UserContent> userContents = new ArrayList<>();
|
|
|
|
|
|
2026-01-28 23:25:16 +07:00
|
|
|
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
private ProtectedFileCheck protectedFileCheck;
|
2026-01-29 19:24:36 +07:00
|
|
|
|
2026-01-30 12:52:16 +07:00
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
|
|
|
@JoinColumn(name = "company_id")
|
|
|
|
|
@ToString.Exclude
|
|
|
|
|
private Company company;
|
|
|
|
|
|
|
|
|
|
@Column(name = "permissions")
|
|
|
|
|
private Long userPermissions = Permission.DEFAULT_USER_PERMISSIONS;
|
|
|
|
|
|
|
|
|
|
@OneToOne(cascade = CascadeType.ALL)
|
|
|
|
|
@JoinColumn(name = "personal_tariff_info_id")
|
|
|
|
|
@ToString.Exclude
|
|
|
|
|
private TariffInfo personalTariffInfo;
|
|
|
|
|
|
2026-02-17 20:17:34 +07:00
|
|
|
@Column(name = "failed_login_attempts")
|
|
|
|
|
@ColumnDefault("0")
|
|
|
|
|
private Integer failedLoginAttempts = 0;
|
|
|
|
|
|
|
|
|
|
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
@ToString.Exclude
|
|
|
|
|
private UserNotActive userNotActive;
|
|
|
|
|
|
2026-04-04 17:38:20 +07:00
|
|
|
@Column(name = "verification_status")
|
2026-04-14 12:57:14 +07:00
|
|
|
@Enumerated(EnumType.STRING)
|
2026-04-04 17:38:20 +07:00
|
|
|
private ModerationStatus verificationStatus = ModerationStatus.NOT_VERIFIED;
|
|
|
|
|
|
2026-01-30 12:52:16 +07:00
|
|
|
public TariffInfo getActiveTariffInfo() {
|
|
|
|
|
if (company != null && company.getTariffInfo() != null) {
|
|
|
|
|
return company.getTariffInfo();
|
|
|
|
|
}
|
|
|
|
|
return personalTariffInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasTariffAccess() {
|
|
|
|
|
TariffInfo activeTariff = getActiveTariffInfo();
|
|
|
|
|
if (activeTariff == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return activeTariff.getStatus() == TariffStatus.ACTIVE &&
|
|
|
|
|
LocalDateTime.now().isBefore(activeTariff.getEndTariff());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean canLogin() {
|
|
|
|
|
return Permission.canLogin(this.userPermissions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean canManageCompanySettings() {
|
|
|
|
|
return Permission.canManageCompanySettings(this.userPermissions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void grantPermission(long permissionBit) {
|
|
|
|
|
this.userPermissions = Permission.addPermission(this.userPermissions, permissionBit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removePermission(long permissionBit) {
|
|
|
|
|
this.userPermissions = Permission.removePermission(this.userPermissions, permissionBit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasPermission(long permissionBit) {
|
|
|
|
|
return Permission.hasPermission(this.userPermissions, permissionBit);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 21:46:37 +07:00
|
|
|
public String getCompanyName() {
|
|
|
|
|
if (company != null) {
|
|
|
|
|
return company.getCompanyName();
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-28 23:25:16 +07:00
|
|
|
}
|