use of cn.edu.zju.acm.onlinejudge.form.ResetPasswordForm in project zoj by licheng.
the class ResetPasswordAction method execute.
/**
* Edit Profile.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
ResetPasswordForm passwordForm = (ResetPasswordForm) form;
String code = passwordForm.getCode();
UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
UserProfile user = null;
if (code != null && code.trim().length() > 0) {
user = userPersistence.getUserProfileByCode(code);
}
if (user == null) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.resetPassword.invalidCode"));
this.saveErrors(context.getRequest(), messages);
return this.handleSuccess(mapping, context, "message");
}
if (passwordForm.getPassword() == null) {
return this.handleSuccess(mapping, context, "failure");
}
user.setPassword(passwordForm.getPassword());
userPersistence.updateUserProfile(user, user.getId());
userPersistence.deleteConfirmCode(user.getId(), user.getId());
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.resetPassword.success"));
this.saveErrors(context.getRequest(), messages);
return this.handleSuccess(mapping, context, "message");
}
Aggregations