diff --git a/src/main/java/org/ntlab/nemophila/models/accounts/AccountManager.java b/src/main/java/org/ntlab/nemophila/models/accounts/AccountManager.java index 1d262f9..45b8dbc 100644 --- a/src/main/java/org/ntlab/nemophila/models/accounts/AccountManager.java +++ b/src/main/java/org/ntlab/nemophila/models/accounts/AccountManager.java @@ -3,27 +3,51 @@ import java.util.HashMap; import java.util.UUID; -public class AccountManager { +public class AccountManager { private static AccountManager theInstance = null; private HashMap accountsMap = new HashMap<>(); + private int newId = 57797; + + private AccountManager() { + + } + //シングルトン化 public static AccountManager getInstance() { if(theInstance == null){ theInstance = new AccountManager(); } return theInstance; } + //アカウントの取得 public Account getAccount(String id){ return accountsMap.get(id); } - public void createAccount(String name, String pw){ + //新規アカウントの作成 + public Account createAccount(String name, String pw){ + //ランダムにトークンを作成 UUID uuid = UUID.randomUUID(); - String id = (String) uuid.toString(); - Account ac = new Account(); + String token = (String) uuid.toString(); + Account ac = new Account(name, pw); + ac.setToken(token); + //IDの作成 + String id = Integer.toString(newId); + ac.setId(id); + newId++; accountsMap.put(id, ac); + return ac; + } + //再ログイン時に新しいトークンを更新する + public Account updateAccount(String id) { + Account ac = accountsMap.get(id); + UUID uuid = UUID.randomUUID(); + String token = (String) uuid.toString(); + ac.setToken(token); + return ac; + } + //アカウント消去 + public void deleteAccount(String id){ + accountsMap.remove(id); + } - } - public Account updateAccount(String id, String pw) { - return null; - } }