Search in sources :

Example 6 with UserPersistence

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");
}
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)

Example 7 with UserPersistence

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);
}
Also used : UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Example 8 with UserPersistence

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");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Aggregations

UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)8 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)7 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)4 ActionMessage (org.apache.struts.action.ActionMessage)4 ActionMessages (org.apache.struts.action.ActionMessages)4 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 ProfileForm (cn.edu.zju.acm.onlinejudge.form.ProfileForm)2 ResetPasswordForm (cn.edu.zju.acm.onlinejudge.form.ResetPasswordForm)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1