diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Account.java b/src/main/java/org/ntlab/acanthus_server/entities/Account.java index 1c6cb4e..0f911e4 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Account.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Account.java @@ -24,8 +24,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import jdk.jshell.execution.LoaderDelegate; import org.ntlab.acanthus_server.models.Gallery; +import javax.xml.crypto.Data; +import java.text.DateFormat; +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.UUID; @@ -54,6 +61,9 @@ private String password; @JsonIgnore private boolean isDummy; + @JsonIgnore + private LocalDateTime lastAccess; + //----------------------------------------------------------------- //コンストラクト @@ -63,6 +73,7 @@ //----------------------------------------------------------------- public Account(Integer uid, String name, String email, String password) { + this.isDummy = false; this.uid = uid; this.name = name; this.email = email; @@ -115,6 +126,7 @@ return (this.token); } + public HashMap getWorkHashMap() { return this.workHashMap; } @@ -149,7 +161,7 @@ //----------------------------------------------------------------- //----------------------------------------------------------------- - // トークンを更新する 藤井 + // トークンを更新する public void updateToken() { if (!isDummy) this.token = UUID.randomUUID().toString(); } @@ -159,7 +171,20 @@ public boolean isMatchedPassword(String password) { return this.password.equals(password); } + //----------------------------------------------------------------- + // トークンのチェック + public boolean isCollectToken(String token){ + var timeoutThreshold = 3; + var nowDateTime = LocalDateTime.now(); + if(lastAccess==null) lastAccess = nowDateTime; + + // 時刻比較 + var duration = Duration.between(lastAccess, nowDateTime).toHours(); + if(duration > timeoutThreshold) return false; + + return token.equals(this.token); + } //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミー @@ -170,6 +195,9 @@ this.email = "d@dummy.com"; this.password = "nittalab"; this.token = "abc"; + this.lastAccess = LocalDateTime.now(); + + //this.lastAccess = LocalDateTime.of(2015, 12, 15, 0, 0); } //----------------------------------------------------------------- }