Search in sources :

Example 1 with ResetPasswordForm

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");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) ResetPasswordForm(cn.edu.zju.acm.onlinejudge.form.ResetPasswordForm) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Aggregations

UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)1 ResetPasswordForm (cn.edu.zju.acm.onlinejudge.form.ResetPasswordForm)1 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)1 ActionMessage (org.apache.struts.action.ActionMessage)1 ActionMessages (org.apache.struts.action.ActionMessages)1