Exemplo n.º 1
0
 public void updateBib(
     final User user, final String town, final String description, final String webSite) {
   final UserImpl userImpl = (UserImpl) user;
   userImpl.setTown(town);
   userImpl.setDescription(description);
   userImpl.setWebSite(webSite);
   entityManager.merge(user);
 }
Exemplo n.º 2
0
 public void facebookConnect(final User user, final Long facebookId) throws NameClashException {
   final UserImpl user1 = (UserImpl) user;
   try {
     user1.setFacebookId(facebookId);
     entityManager.merge(user);
     entityManager.flush();
   } catch (EntityExistsException e) {
     user1.setFacebookId(null);
     throw new NameClashException();
   }
 }
Exemplo n.º 3
0
 public void updateNikePlusData(
     final User user,
     final String nikePlusEmail,
     final String nikePlusPassword,
     final String nikePlusId) {
   final UserImpl userImpl = (UserImpl) user;
   userImpl.setNikePluEmail(nikePlusEmail);
   userImpl.setNikePlusPassword(nikePlusPassword);
   userImpl.setNikePlusId(nikePlusId);
   entityManager.merge(userImpl);
 }
Exemplo n.º 4
0
 public User createUser(final String login, final String password, final String email)
     throws NameClashException, MailException {
   try {
     final UserImpl user = new UserImpl(login, password);
     if (email != null) user.setEmail(email);
     entityManager.persist(user);
     if (email != null) MailSender.sendSignupMail(login, password, email);
     return user;
   } catch (EntityExistsException e) {
     throw new NameClashException();
   }
 }
Exemplo n.º 5
0
 public void forgotPassword(final String email) throws UserNotFoundException, MailException {
   final Query query =
       entityManager.createQuery("select u from UserImpl u where u.email=:cryptedMail");
   query.setParameter("cryptedMail", CipherHelper.cipher(email));
   final List<UserImpl> list = query.getResultList();
   if (list.isEmpty()) throw new UserNotFoundException();
   for (final UserImpl user : list) {
     final String password = Helper.randomstring();
     user.setPassword(password);
     MailSender.forgotPasswordMail(user.getName(), password, email);
     entityManager.merge(user);
   }
 }
Exemplo n.º 6
0
 /** @return null if auth failed, user otherwise */
 public User authenticate(final String login, final String password, final boolean rememberMe) {
   final Query query = query("select u from UserImpl u where u.name=:user_login");
   query.setParameter("user_login", login);
   try {
     final UserImpl user = (UserImpl) query.getSingleResult();
     if (rememberMe && user.getRememberToken() == null) {
       final String token = generateToken();
       user.setRememberToken(token);
       entityManager.merge(user);
     }
     return user.checkPassword(password) ? user : null;
   } catch (NoResultException e) {
     return null;
   }
 }
Exemplo n.º 7
0
 public boolean checkAndChangePassword(
     final User user, final String oldPassword, final String password) throws MailException {
   if (user.checkPassword(oldPassword)) {
     ((UserImpl) user).setPassword(password);
     entityManager.merge(user);
     final UserString email = user.getEmail();
     if (email != null)
       MailSender.sendPasswordChangeMail(user.getName().toString(), password, email.nonEscaped());
     return true;
   }
   return false;
 }
Exemplo n.º 8
0
 public void updateEmail(final User user, final String email) {
   ((UserImpl) user).setEmail(email.length() > 0 ? email : null);
   entityManager.merge(user);
 }
Exemplo n.º 9
0
 public void forgetMe(final User user) {
   ((UserImpl) user).setRememberToken(null);
   entityManager.merge(user);
 }