use of cn.edu.zju.acm.onlinejudge.persistence.UserPersistence 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");
}
use of cn.edu.zju.acm.onlinejudge.persistence.UserPersistence in project zoj by licheng.
the class ForgotPasswordAction method forgotPassword.
public void forgotPassword(UserProfile user, ContextAdapter context) throws Exception {
UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
String code = RandomStringGenerator.generate();
userPersistence.createConfirmCode(user.getId(), code, user.getId());
String url = ConfigManager.getValue("home_url") + context.getRequest().getContextPath() + "/resetPassword.do?code=" + code;
EmailService.sendPasswordEmail(user, url);
}
use of cn.edu.zju.acm.onlinejudge.persistence.UserPersistence in project zoj by licheng.
the class ForgotPasswordAction method execute.
/**
* Login.
*
* <pre>
* </pre>
*
* @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 {
if (!Features.forgotPassword()) {
context.getResponse().sendError(404);
return null;
}
String handle = context.getRequest().getParameter("handle");
String email = context.getRequest().getParameter("email");
if ((handle == null || handle.trim().length() == 0) && (email == null || email.trim().length() == 0)) {
return this.handleSuccess(mapping, context, "success");
}
UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
UserProfile user = null;
if (handle != null && handle.trim().length() > 0) {
user = userPersistence.getUserProfileByHandle(handle);
}
if (user == null) {
if (email != null && email.trim().length() > 0) {
user = userPersistence.getUserProfileByEmail(email.trim());
}
}
if (user != null) {
forgotPassword(user, context);
context.setAttribute("ok", Boolean.TRUE);
} else {
context.setAttribute("ok", Boolean.FALSE);
}
context.setAttribute("email", email);
context.setAttribute("handle", handle);
return this.handleSuccess(mapping, context, "success");
}
Aggregations