All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.foodtechlab.lib.auth.service.domain.confirmationCode.entity.ConfirmationCodeEntity Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package ru.foodtechlab.lib.auth.service.domain.confirmationCode.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import ru.foodtechlab.abe.domain.entities.BaseDeleteEntity;
import ru.foodtechlab.lib.auth.service.domain.auth.entity.AuthSessionEntity;

import java.time.Instant;

@Getter
@Setter
@NoArgsConstructor
@SuperBuilder
public class ConfirmationCodeEntity extends BaseDeleteEntity {

    /**
     * Проверочный код
     */
    private String code;
    private String message = "";
    private String header = "";
    private String webhookProviderUrl;
    /**
     * Получатель
     */
    private AuthSessionEntity authSession;
    private ConfirmationCodeDestinationType confirmationCodeDestinationType;
    private Type type;
    /**
     * Статус подтверждения кода
     */
    private ConfirmationStatus confirmationStatus = ConfirmationStatus.NOT_CONFIRMED;

    /**
     * Время подтверждения
     */
    private Instant confirmationAt;

    public enum Type {
        ONE_TIME, PERSONAL, GENERAL
    }

    public enum ConfirmationStatus {
        NOT_CONFIRMED, CONFIRMED, EXPIRED, INVALIDATED
    }

    /**
     * Methods
     */

    public void invalidate() {
        this.confirmationStatus = ConfirmationStatus.INVALIDATED;
    }

    public void expire() {
        this.confirmationStatus = ConfirmationStatus.EXPIRED;
    }

    public void confirm() {
        this.confirmationStatus = ConfirmationStatus.CONFIRMED;
        this.confirmationAt = Instant.now();
    }

    public boolean isExpired() {
        return Instant.now().isAfter(this.authSession.getExpiredAt());
    }




}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy