/** * Sign up: add a new record to both Account and Profile repositories. * * @param login * @param password * @param profile * @return access token */ public String createAccount(String login, String password, String role, Profile profile) throws ServiceException { /* Check if this account already exists. */ Account userAccount = accountDAO.getAccount(login, null); if (userAccount != null) { throw new ServiceException("Account already exists."); } // Get the current time final Long currentTimeMillis = System.currentTimeMillis(); // Wrap up an account object Account account = new Account(); account.setPassword(password); account.setLogin(login); account.setRoles(role); account.setActivated(true); account.setCtime(currentTimeMillis); account.setUtime(currentTimeMillis); // Wrap up a profile object profile.setCtime(currentTimeMillis); profile.setUtime(currentTimeMillis); // create the account and profile Account ret = createAccountInternal(account, profile); if (ret == null) { throw new ServiceException("An internal error happened while creating your " + "account."); } return ret.getAccessToken(); }
/** Return an access token string after successfully login. */ private String refreshAccessToken(String username) { String token = TokenHandler.createTokenForUser(username); Account account = new Account(); account.setLogin(username); account.setAccessToken(token); account.setUtime(System.currentTimeMillis()); accountDAO.updateAccount(account); return token; }