use of com.jappstart.model.auth.UserAccount in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method loadUserByUsername.
/**
* Locates the user based on the username.
*
* @param username string the username
* @return the user details
*/
@Override
public final UserDetails loadUserByUsername(final String username) {
final List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
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) {
throw new UsernameNotFoundException("Username not found.", e);
}
}
authorities.add(new SimpleGrantedAuthority(user.getRole()));
return new EnhancedUser(user.getUsername(), user.getEmail(), user.getDisplayName(), user.getPassword(), user.getSalt(), user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonLocked(), authorities);
}
use of com.jappstart.model.auth.UserAccount in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method activationEmailSent.
/**
* Updates the activation e-mail sent status.
*
* @param username the username
*/
@Override
@Transactional
public final void activationEmailSent(final String username) {
final Query query = entityManager.createQuery(SELECT_USER);
query.setParameter(USERNAME, username);
try {
final UserAccount user = (UserAccount) query.getSingleResult();
user.setActivationEmailSent(true);
entityManager.persist(user);
memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
} catch (NoResultException e) {
throw new UsernameNotFoundException("Username not found.", e);
}
}
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 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;
}
}
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);
}
Aggregations