Beispiel #1
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 #2
0
 /**
  * Saves new user to database, user is checked for being null value, depending on userType, seller
  * doesn't have to authenticate email address.
  *
  * @param user <code>AppUser</code> type value of user
  * @param userType <code>String</code> type value of user type
  * @return <code>boolean</code> type value if user is successfully saved to database, false if not
  */
 public static boolean saveNewUser(AppUser user, String userType) {
   if (user != null) {
     user.hashPass();
     user.token = UUID.randomUUID().toString();
     user.androidToken = UUID.randomUUID().toString();
     if (Constants.USER_SELLER.equals(userType)) {
       user.userAccessLevel = UserAccessLevel.SELLER;
       user.validated = Constants.VALIDATED_USER;
     }
     try {
       user.save();
       return true;
     } catch (PersistenceException e) {
       ErrorLogger.createNewErrorLogger(
           "Failed to save user. Possible duplicate email entry.", e.getMessage());
       return false;
     }
   }
   return false;
 }