Search in sources :

Example 1 with PersistentUser

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);
    }
}
Also used : PersistentUser(com.jappstart.model.auth.PersistentUser) Query(javax.persistence.Query) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with 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));
}
Also used : PersistentUser(com.jappstart.model.auth.PersistentUser) Query(javax.persistence.Query) PersistentLogin(com.jappstart.model.auth.PersistentLogin) UserAccount(com.jappstart.model.auth.UserAccount) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PersistentUser (com.jappstart.model.auth.PersistentUser)2 Query (javax.persistence.Query)2 Transactional (org.springframework.transaction.annotation.Transactional)2 PersistentLogin (com.jappstart.model.auth.PersistentLogin)1 UserAccount (com.jappstart.model.auth.UserAccount)1