/** * Validates user * * @param user * @return */ public static boolean validateUser(AppUser user) { if (user == null) { return false; } user.token = null; user.validated = true; user.update(); return true; }
/** * 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; }
/** * Updates user profile with new values and adds a picture to user profile if one is selected. * * @param user <code>AppUser</code> type value of user * @param password <code>String</code> type value of user password * @param name <code>String</code> type value of user name * @param lastname <code>String</code> type value of user lastname * @param phone <code>String</code> type value of user phone * @param profileImage <code>Image</code> type value of user profile image * @return <code>boolean</code> type value true if user profile was successfully updated, false if * not */ public static boolean updateUserProfile( AppUser user, String password, String name, String lastname, String phone, Image profileImage) { if (user != null) { try { user.firstname = name; user.lastname = lastname; user.password = password; user.hashPass(); user.phoneNumber = phone; if (profileImage != null) { user.profileImg = profileImage; } user.update(); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger("Failed to update user profile.", e.getMessage()); return false; } } return false; }
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; }
/** * 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; }
/** * 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; }
/** * Clears the forgotten password token field for provided user * * @param user */ public static void clearChangePasswordToken(AppUser user) { user.forgottenPassToken = null; user.save(); }
/** * Hashes the new password and saves it into the database. * * <p>Clears the forgotten password token field in the database * * @param user * @param newPassword * @return */ public void updatePassword(AppUser user, String newPassword) { user.password = newPassword; user.hashPass(); user.forgottenPassToken = null; user.save(); }