49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package ru.soune.nocopy.entity;
|
|
|
|
import jakarta.persistence.*;
|
|
import lombok.*;
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@Entity
|
|
@Table(name = "auth_tokens")
|
|
@Getter
|
|
@Setter
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
@ToString
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
public class AuthToken {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long tokenId;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "user_id", nullable = false)
|
|
@ToString.Exclude
|
|
private User user;
|
|
|
|
@Column(nullable = false, unique = true, length = 64)
|
|
private String token;
|
|
|
|
@Column(name = "expires_at", nullable = false)
|
|
private LocalDateTime expiresAt = LocalDateTime.now().plusDays(30);
|
|
|
|
@CreatedDate
|
|
@Column(name = "created_at", updatable = false, nullable = false)
|
|
private LocalDateTime createdAt;
|
|
|
|
@Column(name = "last_used_at")
|
|
private LocalDateTime lastUsedAt;
|
|
|
|
@Column(name = "is_active")
|
|
private Boolean isActive = true;
|
|
|
|
public boolean isValid() {
|
|
return Boolean.TRUE.equals(isActive) && expiresAt.isAfter(LocalDateTime.now());
|
|
}
|
|
}
|