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 d2fae52..127c775 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Account.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Account.java @@ -67,9 +67,8 @@ //----------------------------------------------------------------- //コンストラクト - public Account() { - var numOfAccounts = 2; - for(int i = 0; i < numOfAccounts; i++) createDummyAccount(i); + public Account(Integer idMargin) { + createDummyAccount(idMargin); } //----------------------------------------------------------------- @@ -172,20 +171,22 @@ public boolean isMatchedPassword(String password) { return this.password.equals(password); } + //----------------------------------------------------------------- // トークンのチェック - public boolean isCollectToken(String token){ + public boolean isCollectToken(String token) { var timeoutThreshold = 3; var nowDateTime = LocalDateTime.now(); - if(lastAccess==null) lastAccess = nowDateTime; + if (lastAccess == null) lastAccess = nowDateTime; // 時刻比較 var duration = Duration.between(lastAccess, nowDateTime).toHours(); - if(duration > timeoutThreshold) return false; + if (duration > timeoutThreshold) return false; return token.equals(this.token); } + //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミー @@ -193,7 +194,7 @@ this.isDummy = true; this.uid = 1 + idMargin; this.name = "dummy" + idMargin.toString(); - this.email = "d"+ idMargin.toString() +"@dummy.com"; + this.email = "d" + idMargin.toString() + "@dummy.com"; this.password = "nittalab"; this.token = "abc" + idMargin.toString(); this.lastAccess = LocalDateTime.now(); diff --git a/src/main/java/org/ntlab/acanthus_server/models/Accounts.java b/src/main/java/org/ntlab/acanthus_server/models/Accounts.java index 92a0020..7dfa63d 100644 --- a/src/main/java/org/ntlab/acanthus_server/models/Accounts.java +++ b/src/main/java/org/ntlab/acanthus_server/models/Accounts.java @@ -2,6 +2,7 @@ import org.ntlab.acanthus_server.entities.Account; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -20,7 +21,7 @@ //----------------------------------------------------------------- // インスタンス生成禁止 private Accounts() { - createDummyAccount(); //ダミー + createDummyAccounts(2); } //----------------------------------------------------------------- @@ -40,6 +41,7 @@ //----------------------------------------------------------------- // Uidからアカウントを返す + /** * @param uid ユーザーID */ @@ -49,6 +51,7 @@ //----------------------------------------------------------------- // e-mailからアカウントを返す + /** * @param email メアド */ @@ -61,6 +64,7 @@ //----------------------------------------------------------------- // 名前からアカウントのリストを返す + /** * @param name ユーザー名 */ @@ -75,28 +79,36 @@ } //----------------------------------------------------------------- // アカウントを登録する. + /** - * @param name ユーザー名 - * @param email メアド + * @param name ユーザー名 + * @param email メアド * @param password パスワード */ public Account registerAccount(String name, String email, String password) { var uid = new Random().nextInt(); // uidが被ったらuidの振り直し - while(getAccountByUid(uid) != null) uid = new Random().nextInt(); + while (getAccountByUid(uid) != null) uid = new Random().nextInt(); - var newAccount = new Account (uid, name, email, password); + var newAccount = new Account(uid, name, email, password); accountHashMap.put(uid, newAccount); return newAccount; } + //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミーアカウント生成 - private void createDummyAccount(){ - var dummyAccount = new Account(); + private void createDummyAccount(Integer idMargin) { + var dummyAccount = new Account(idMargin); accountHashMap.put(dummyAccount.getUid(), dummyAccount); } + //----------------------------------------------------------------- + // ダミーを指定数生成 + private void createDummyAccounts(int numOfAccounts) { + for (int i = 0; i < numOfAccounts; i++) createDummyAccount(i); //ダミー + } + }