logger.info("userList: " + userList.size());
if (userList.isEmpty()) {
//No user, request registration
BasicSession newSession = new BasicSession();
newSession.setUuid(UUID.randomUUID().toString());
newSession.setEmail(email);
newSession.setExpiry(expiry);
newSession.setAccountName("__NEW__");
//userHash.put(newUser.getId(), newUser);
logger.info("Persisting new Session: " + new Gson().toJson(newSession));
getAccountService().persistSession(newSession);
jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "false}";
} else if (userList.size() == 1) {
//One user with one account, return correct uuid
User user = userList.get(0);
//userHash.put(user.getId(), new BasicUser(user));
logger.info("One User: " + new Gson().toJson(user));
BasicSession newSession = new BasicSession();
newSession.setUuid(UUID.randomUUID().toString());
newSession.setEmail(email);
newSession.setExpiry(expiry);
newSession.setAccountName(user.getAccountName());
getAccountService().persistSession(newSession);
logger.info("Updating Session: " + new Gson().toJson(newSession));
jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "true}";
} else if (userList.size() > 1) {
//One user with multiple accounts, return list of accounts
jsonResponse = "{\"error\": \"not_yet_implemented\"}";
}
} else if (isPost(e) && uri.endsWith("/auth/register") && cookieUuidToken != null) {
logger.info("isPost /auth/register. Cookie: " + cookieUuidToken);
Session session = null;
if (cookieUuidToken != null) {
session = getAccountService().getSession(cookieUuidToken);
}
if (session != null) {
BasicSession updatedSession = new BasicSession(session);
BasicUser httpUser = ParseJsonObjects.parseUser(jsonObject);
logger.info("HTTP user: " + new Gson().toJson(httpUser));
updatedSession.setAccountName(httpUser.getAccountName());
getAccountService().persistSession(updatedSession);
logger.info("persisted new session: " + new Gson().toJson(updatedSession));
BasicUser newUser = new BasicUser(httpUser);
newUser.setUserRole("admin");
newUser.setUserName(session.getEmail());
getAccountService().persistUser(newUser);
logger.info("persisted user: " + new Gson().toJson(newUser));
BasicAccount newAccount = new BasicAccount();
newAccount.setId(httpUser.getAccountName());
newAccount.setAccountType("new");
getAccountService().persistAccount(newAccount);
jsonResponse = "{ \"registered\": " + "true, \"uuidToken\": \"" + updatedSession.getUuid() + "\"}";
} else {
jsonResponse = "{ \"registered\": " + "false}";
}
logger.info(jsonObject);