Skip to content

Instantly share code, notes, and snippets.

@andresamayadiaz
Created January 28, 2012 03:41
Show Gist options
  • Save andresamayadiaz/1692460 to your computer and use it in GitHub Desktop.
Save andresamayadiaz/1692460 to your computer and use it in GitHub Desktop.
Play Password Change
public static void update(User entity, String repassword, boolean chgPassword) {
Gson gson = new Gson();
Logger.info("ENTITY 1: "+gson.toJson(entity));
// Validate Password Change
if(chgPassword){
if(!entity.password.equals(repassword)){
validation.addError("repassword", "Password does not match!");
render("@edit", entity);
}
if(entity.password.equals("")){
validation.addError("entity.password", "Password cannot be empty!");
render("@edit", entity);
}
}else {
User usr = User.findById(entity.id);
Logger.info("USER: "+gson.toJson(usr));
Logger.info("ENTITY 2: "+gson.toJson(entity));
//Logger.info("ID: [%s] - Set same password = %s", entity.id, usr.password);
entity.password = usr.password;
}
validation.valid(entity);
if (validation.hasErrors()) {
render("@edit", entity);
}
entity = entity.merge();
entity.save();
flash.success(Messages.get("user.updated", "User"));
index();
}
@andresamayadiaz
Copy link
Author

Here is the Output:
21:45:44,098 INFO ~ EDIT ENTITY: {"userName":"jorge@email.com","fullName":"Jorge Lopez Perez","password":"123","isAdmin":true,"id":3}
21:45:53,701 INFO ~ ENTITY 1: {"userName":"jorge@email.com","fullName":"Jorge Lopez","password":"","isAdmin":true,"id":3}
21:45:53,702 INFO ~ USER: {"userName":"jorge@email.com","fullName":"Jorge Lopez","password":"","isAdmin":true,"id":3}
21:45:53,702 INFO ~ ENTITY 2: {"userName":"jorge@email.com","fullName":"Jorge Lopez","password":"","isAdmin":true,"id":3}

The EDIT ENTITY is the User info when i enter the edit method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment