@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { ParticipantId participant = sessionManager.getLoggedInUser(req.getSession(false)); if (participant == null) { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } String locale = URLDecoder.decode(req.getParameter("locale"), "UTF-8"); AccountData account = accountStore.getAccount(participant); HumanAccountData humanAccount; if (account != null) { humanAccount = account.asHuman(); } else { humanAccount = new HumanAccountDataImpl(participant); } humanAccount.setLocale(locale); accountStore.putAccount(humanAccount); } catch (PersistenceException ex) { throw new IOException(ex); } } }
String locale = account.asHuman().getLocale(); if (locale != null) { String requestLocale = UrlParameters.getParameters(request.getQueryString()).get("locale");
} else if (!account.asHuman().getPasswordDigest().verify(password)) {
public void testRegisterNewUserEnabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", false); verify(resp).setStatus(HttpServletResponse.SC_OK); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("internet".toCharArray())); verify(welcomeBot).greet(eq(participantId)); }
public void testRegisterNewUserEnabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", false); verify(resp).setStatus(HttpServletResponse.SC_OK); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("internet".toCharArray())); verify(welcomeBot).greet(eq(participantId)); }
@Override public void putAccount(AccountData account) { DBObject object = getDBObjectForParticipant(account.getId()); if (account.isHuman()) { object.put(ACCOUNT_HUMAN_DATA_FIELD, humanToObject(account.asHuman())); } else if (account.isRobot()) { object.put(ACCOUNT_ROBOT_DATA_FIELD, robotToObject(account.asRobot())); } else { throw new IllegalStateException("Account is neither a human nor a robot"); } getAccountCollection().save(object); }
public void testNullPasswordWorks() throws Exception { attemptToRegister(req, resp, "zd@example.com", null, false); verify(resp).setStatus(HttpServletResponse.SC_OK); AccountData account = store.getAccount(ParticipantId.ofUnsafe("zd@example.com")); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("".toCharArray())); }
public void testNullPasswordWorks() throws Exception { attemptToRegister(req, resp, "zd@example.com", null, false); verify(resp).setStatus(HttpServletResponse.SC_OK); AccountData account = store.getAccount(ParticipantId.ofUnsafe("zd@example.com")); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("".toCharArray())); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }
/** * Serialize {@link AccountData} into {@link ProtoAccountData}. */ public static ProtoAccountData serialize(AccountData account) { Preconditions.checkNotNull(account, "account is null"); Preconditions.checkArgument(account.isHuman() || account.isRobot(), "account is neither a human or robot account!"); ProtoAccountData.Builder builder = ProtoAccountData.newBuilder(); builder.setAccountId(account.getId().getAddress()); if (account.isHuman()) { builder.setAccountType(AccountDataType.HUMAN_ACCOUNT); builder.setHumanAccountData(serialize(account.asHuman())); } else if (account.isRobot()) { builder.setAccountType(AccountDataType.ROBOT_ACCOUNT); builder.setRobotAccountData(serialize(account.asRobot())); } return builder.build(); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }