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