diff --git a/src/main/java/cactusServer/models/Accounts.java b/src/main/java/cactusServer/models/Accounts.java index 5be7d51..467956d 100644 --- a/src/main/java/cactusServer/models/Accounts.java +++ b/src/main/java/cactusServer/models/Accounts.java @@ -26,7 +26,7 @@ public Account createAcount(String userID, String userName, String userPass) { System.out.println(userName); - if(!idSet.add(userID)) { + if (!idSet.add(userID)) { return null; } Account newAccount = new Account(userName, userPass); @@ -36,39 +36,49 @@ return newAccount; } - public Account getAccount(String userID) { - if(idSet.contains(userID)) { - Account editAccount = accounts.get(userID); - return editAccount; - }else { + public Account updateAccount(String userID, String userName, String userPass) { + if (idSet.contains(userID)) { + Accounts.getInstance().getAccount(userID).setName(userName); + Accounts.getInstance().getAccount(userID).setPass(userPass); + return Accounts.getInstance().getAccount(userID); + } else { return null; } } - public Account loginAccount(String userID,String userPass) { - if(idSet.contains(userID) && getAccount(userID).getPass().equals(userPass)) { - Accounts.getInstance().getAccount(userID).setLogin(true); - return getAccount(userID); - }else { + public Account getAccount(String userID) { + if (idSet.contains(userID)) { + Account editAccount = accounts.get(userID); + return editAccount; + } else { return null; } } - + + public Account loginAccount(String userID, String userPass) { + if (idSet.contains(userID) && getAccount(userID).getPass().equals(userPass)) { + Accounts.getInstance().getAccount(userID).setLogin(true); + return getAccount(userID); + } else { + return null; + } + } + public String logoutAccount(String userID) { - if(idSet.contains(userID)) { + if (idSet.contains(userID)) { Accounts.getInstance().getAccount(userID).setLogin(false); return "success"; - }else { + } else { return "null"; } } - + public String deleteAccount(String userID) { - if(idSet.contains(userID)) { + if (idSet.contains(userID)) { accounts.remove(userID); idSet.remove(userID); return "complated remove account"; - }else { + } else { return "not exist"; } }