Search in sources :

Example 31 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile 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)

Example 32 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class ShowSubmissionAction method execute.

/**
 * ShowSourceAction.
 *
 * @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 {
    HttpServletResponse response = context.getResponse();
    long id = Utility.parseLong(context.getRequest().getParameter("submissionId"));
    Submission submission = ContestManager.getInstance().getSubmission(id);
    if (submission == null) {
        response.sendError(404);
        return null;
    }
    // user can always view their own submission
    UserProfile user = context.getUserProfile();
    if (user == null || user.getId() != submission.getUserProfileId()) {
        Problem problem = ContestManager.getInstance().getProblem(submission.getProblemId());
        context.setAttribute("problem", problem);
        ActionForward forward = this.checkProblemViewSourecPermission(mapping, context, null);
        if (forward != null) {
            response.sendError(404);
            return null;
        }
    }
    response.setContentType("text/plain");
    boolean download = "true".equalsIgnoreCase(context.getRequest().getParameter("download"));
    if (download) {
        response.setHeader("Content-disposition", "attachment; filename=" + id + "." + submission.getLanguage().getOptions());
    }
    response.getOutputStream().write(submission.getContent().getBytes());
    response.getOutputStream().close();
    return null;
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) HttpServletResponse(javax.servlet.http.HttpServletResponse) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward)

Aggregations

UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)32 ActionForward (org.apache.struts.action.ActionForward)9 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)7 ActionMessage (org.apache.struts.action.ActionMessage)6 ActionMessages (org.apache.struts.action.ActionMessages)6 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)3 Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)3 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 List (java.util.List)3