Beispiel #1
0
 /**
  * Deletes specific user from database, user is foundby provided email.
  *
  * @param email <code>String</code> type alue of email
  * @return <code>boolean</code> type value true if user is successfully deleted, false if not
  */
 public static boolean deleteUser(String email) {
   AppUser user = AppUser.getUserByEmail(email);
   if (user != null) {
     try {
       user.delete();
       return true;
     } catch (PersistenceException e) {
       ErrorLogger.createNewErrorLogger("Failed to delete user.", e.getMessage());
       return false;
     }
   }
   return false;
 }
Beispiel #2
0
 /**
  * Changes role of user, new role is taken from html selection box. User is found with provided
  * email.
  *
  * @param email <code>String</code> type value of user email
  * @param role <code>String</code> type value of new user role
  * @return <code>boolean</code> type value true if user is successfully updated, false if not
  */
 public static boolean changeUserRole(String email, String role) {
   AppUser user = AppUser.getUserByEmail(email);
   if (user != null) {
     if ("buyer".equals(role)) {
       user.userAccessLevel = UserAccessLevel.BUYER;
     } else if ("seller".equals(role)) {
       user.userAccessLevel = UserAccessLevel.SELLER;
     } else if ("hotelmanager".equals(role)) {
       user.userAccessLevel = UserAccessLevel.HOTEL_MANAGER;
     }
     try {
       user.update();
       return true;
     } catch (PersistenceException e) {
       ErrorLogger.createNewErrorLogger("Failed to change user role.", e.getMessage());
       return false;
     }
   }
   return false;
 }
Beispiel #3
0
 public static boolean activateForgottenPassword(String email) {
   AppUser user = AppUser.getUserByEmail(email);
   if (user != null) {
     try {
       user.forgottenPassToken = UUID.randomUUID().toString();
       user.update();
       // Sending Email To user
       String host =
           Play.application().configuration().getString("url")
               + "user/forgotyourpassword/"
               + user.forgottenPassToken;
       String cancelRequest =
           Play.application().configuration().getString("url")
               + "user/cancelpasswordchangerequest/"
               + user.forgottenPassToken;
       MailHelper.send(user.email, host, Constants.CHANGE_PASSWORD, cancelRequest, null, null);
       return true;
     } catch (PersistenceException e) {
       ErrorLogger.createNewErrorLogger("Failed to set password reset token.", e.getMessage());
       return false;
     }
   }
   return false;
 }