use of com.jappstart.model.auth.UserAccount 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));
}
use of com.jappstart.model.auth.UserAccount in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method getUser.
/**
* Returns the user account for the given username.
*
* @param username the username
* @return the user account
*/
@Override
public final UserAccount getUser(final String username) {
UserAccount user = (UserAccount) memcacheService.get(username);
if (user == null) {
final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE username = :username");
query.setParameter(USERNAME, username);
try {
user = (UserAccount) query.getSingleResult();
memcacheService.put(username, user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
} catch (NoResultException e) {
return null;
}
}
return user;
}
use of com.jappstart.model.auth.UserAccount in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method addUser.
/**
* Adds a user.
*
* @param user the user
* @param locale the locale
*/
@Override
@Transactional
public final void addUser(final UserAccount user, final Locale locale) {
final UserAccount cachedUser = (UserAccount) memcacheService.get(user.getUsername());
if (cachedUser != null) {
throw new DuplicateUserException();
}
final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE username = :username");
query.setParameter(USERNAME, user.getUsername());
@SuppressWarnings("unchecked") final List results = query.getResultList();
if (results != null && !results.isEmpty()) {
throw new DuplicateUserException();
}
entityManager.persist(user);
memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
final TaskOptions taskOptions = TaskOptions.Builder.withUrl(mailTaskUrl).param("username", user.getUsername()).param("locale", locale.toString());
final Queue queue = QueueFactory.getQueue(mailTaskName);
queue.add(datastoreService.getCurrentTransaction(), taskOptions);
}
use of com.jappstart.model.auth.UserAccount in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method activateUser.
/**
* Activates the user with the given activation key.
*
* @param key the activation key
* @return true if successful; false otherwise
*/
@Override
@Transactional
public final boolean activateUser(final String key) {
final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE activationKey = :key");
query.setParameter("key", key);
try {
final UserAccount user = (UserAccount) query.getSingleResult();
user.setEnabled(true);
entityManager.persist(user);
memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
return true;
} catch (NoResultException e) {
return false;
}
}
Aggregations