Newer
Older
CactusServer / src / main / java / cactusServer / models / Accounts.java
y-ota on 17 May 2018 1 KB new branch
package cactusServer.models;

import javax.inject.Singleton;

import cactusServer.entities.Account;

import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;

@Singleton
public class Accounts {
	private static Accounts theInstance = null;
	private HashMap<String, Account> accounts = new HashMap<>();
	private HashSet<String> idList = new HashSet<String>();

	private Accounts() {

	}

	public static Accounts getInstance() {
		if (theInstance == null) {
			theInstance = new Accounts();
		}
		return theInstance;
	}

	public Account createAcount(String userID, String userName, String userPass) {
		System.out.println(userName);
		if(!idList.add(userID)) {
			return null;
		}
		Account newAccount = new Account(userName, userPass);
		accounts.put(userID, newAccount);
		System.out.println(userID);

		return newAccount;
	}

	public Account getAccount(String userID) {
		Account editAccount = accounts.get(userID);
		return editAccount;
	}

	public URI loginAccount(String userID,String userPass) {
		if(idList.contains(userID)) {
			return URI.create("http:");
		}else {
			return URI.create("failed login attempt");
		}
	}
	
	public String logoutAccount(String userID) {
		Accounts.getInstance().getAccount(userID).setLogin(false);
		return "success";
	}
	
	public String deleteAccount(String userID) {
		accounts.remove(userID);
		return "complated remove account";
	}

}