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);
} else if (isGet(e) && cookieUuidToken != null) {
logger.info("isGet: " + cookieUuidToken);
Session cookieSession = getAccountService().getSession(cookieUuidToken);
logger.info("cookieSession: " + new Gson().toJson(cookieSession));
if (cookieSession != null && cookieSession.getEmail() != null) {
User sessionUser = getAccountService().getUser(cookieSession.getEmail(), cookieSession.getAccountName());
logger.info("sessionUser: " + new Gson().toJson(sessionUser));
if (getRootUser() != null && sessionUser != null && sessionUser.getUserName().equals(getRootUser())) {
BasicUser rootUser = new BasicUser(sessionUser);
rootUser.setUserRole("root");
jsonResponse = "{\"user\": " + new Gson().toJson(rootUser) + "}";
logger.info("Returning user: " + jsonResponse);
} else if (sessionUser != null ) {
jsonResponse = "{\"user\": " + new Gson().toJson(sessionUser) + "}";
logger.info("Returning user: " + jsonResponse);