diff --git a/src/main/java/cactusServer/models/Accounts.java b/src/main/java/cactusServer/models/Accounts.java index a70293f..5be7d51 100644 --- a/src/main/java/cactusServer/models/Accounts.java +++ b/src/main/java/cactusServer/models/Accounts.java @@ -11,7 +11,7 @@ public class Accounts { private static Accounts theInstance = null; private HashMap accounts = new HashMap<>(); - private HashSet idList = new HashSet(); + private HashSet idSet = new HashSet(); private Accounts() { @@ -26,7 +26,7 @@ public Account createAcount(String userID, String userName, String userPass) { System.out.println(userName); - if(!idList.add(userID)) { + if(!idSet.add(userID)) { return null; } Account newAccount = new Account(userName, userPass); @@ -37,12 +37,16 @@ } public Account getAccount(String userID) { - Account editAccount = accounts.get(userID); - return editAccount; + if(idSet.contains(userID)) { + Account editAccount = accounts.get(userID); + return editAccount; + }else { + return null; + } } public Account loginAccount(String userID,String userPass) { - if(idList.contains(userID) && getAccount(userID).getPass().equals(userPass)) { + if(idSet.contains(userID) && getAccount(userID).getPass().equals(userPass)) { Accounts.getInstance().getAccount(userID).setLogin(true); return getAccount(userID); }else { @@ -51,13 +55,22 @@ } public String logoutAccount(String userID) { - Accounts.getInstance().getAccount(userID).setLogin(false); - return "success"; + if(idSet.contains(userID)) { + Accounts.getInstance().getAccount(userID).setLogin(false); + return "success"; + }else { + return "null"; + } } public String deleteAccount(String userID) { - accounts.remove(userID); - return "complated remove account"; + if(idSet.contains(userID)) { + accounts.remove(userID); + idSet.remove(userID); + return "complated remove account"; + }else { + return "not exist"; + } } }