public void updateTrack(final User user, final long id, final String title, final String points)
     throws TrackNotFoundException, AccessDeniedException {
   final TrackImpl track = fetchTrackForUpdate(user, id);
   track.setTitle(title);
   track.setPoints(points);
   entityManager.merge(track);
 }
 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);
 }
 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();
   }
 }
 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);
 }
 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;
 }
 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);
   }
 }
 /** @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;
   }
 }
 public ConversationData fetchConvertationData(
     final User sender, final String receiver, final Long aboutWorkoutId, final int startIndex)
     throws WorkoutNotFoundException {
   final Workout aboutWorkout =
       aboutWorkoutId == null ? null : workoutStore.fetchWorkout(aboutWorkoutId);
   final ConversationData conversationData =
       new ConversationData(
           fetchConversation(sender, receiver, startIndex),
           aboutWorkout,
           UserStringImpl.valueOf(receiver));
   for (final PrivateMessage privateMessage : conversationData.privateMessages) {
     final PrivateMessageImpl message1 = (PrivateMessageImpl) privateMessage;
     if (!message1.isRead() && message1.getReceiver().equals(sender)) {
       message1.setRead(true);
       message1.setNew(true);
       entityManager.merge(privateMessage);
     }
   }
   return conversationData;
 }
 public void updateEmail(final User user, final String email) {
   ((UserImpl) user).setEmail(email.length() > 0 ? email : null);
   entityManager.merge(user);
 }
 public void forgetMe(final User user) {
   ((UserImpl) user).setRememberToken(null);
   entityManager.merge(user);
 }