use of com.jappstart.model.auth.PersistentUser in project google-app-engine-jappstart by taylorleese.
the class PersistentTokenRepositoryImpl method removeUserTokens.
/**
* Removes the tokens for the given username.
*
* @param username the username
*/
@Override
@Transactional
public final void removeUserTokens(final String username) {
final Query query = entityManager.createQuery("SELECT p FROM PersistentUser p WHERE username = :username");
query.setParameter("username", username);
if (query.getResultList().size() > 0) {
final PersistentUser persistentUser = (PersistentUser) query.getSingleResult();
entityManager.remove(persistentUser);
}
}
use of com.jappstart.model.auth.PersistentUser in project google-app-engine-jappstart by taylorleese.
the class PersistentTokenRepositoryImpl method createNewToken.
/**
* Creates a new remember me token.
*
* @param token the remember me token
*/
@Override
@Transactional
public final void createNewToken(final PersistentRememberMeToken token) {
final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE username = :username");
query.setParameter("username", token.getUsername());
final UserAccount user = (UserAccount) query.getSingleResult();
if (user.getPersistentUser() == null) {
user.setPersistentUser(new PersistentUser(user.getKey(), token.getUsername()));
}
if (user.getPersistentUser().getPersistentLogins() == null) {
user.getPersistentUser().setPersistentLogins(new ArrayList<PersistentLogin>());
}
user.getPersistentUser().getPersistentLogins().add(createPersistentLogin(user.getPersistentUser().getKey(), token));
entityManager.persist(user);
memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
}
Aggregations