use of org.apache.struts.action.ActionMessages in project zoj by licheng.
the class BaseAction method checkLastLoginIP.
protected ActionForward checkLastLoginIP(ActionMapping mapping, ContextAdapter context, boolean isProblemset) throws Exception {
String ip = context.getRequest().getRemoteHost();
long contestId = context.getContest().getId();
String ipSessionKey = "last_submit_ip" + contestId;
String lastIp = (String) context.getSessionAttribute(ipSessionKey);
if (lastIp == null) {
ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
long userId = context.getUserProfile().getId();
lastIp = contestPersistence.getLastSubmitIP(userId, contestId);
if (lastIp == null) {
// first submit
contestPersistence.setLastSubmitIP(userId, contestId, ip);
context.setSessionAttribute(ipSessionKey, lastIp);
return null;
}
context.setSessionAttribute(ipSessionKey, lastIp);
}
if (!lastIp.equals(ip)) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.submit.invalid_ip"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "contestInfo.do?contestId=" + contestId);
return this.handleFailure(mapping, context, messages, "nopermission");
}
return null;
}
use of org.apache.struts.action.ActionMessages in project zoj by licheng.
the class BaseAction method checkContestPermission.
protected ActionForward checkContestPermission(ActionMapping mapping, ContextAdapter context, Boolean isProblemset, boolean checkStart, PermissionLevel level) throws Exception {
// get the contest
AbstractContest contest = context.getContest();
if (contest == null || isProblemset != null && (contest instanceof Contest || contest instanceof Course) == isProblemset.booleanValue()) {
context.setAttribute("contest", null);
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.showcontest.nocontestid"));
this.saveErrors(context.getRequest(), messages);
if (isProblemset != null) {
context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
}
return this.handleFailure(mapping, context, messages, "nopermission");
}
context.setAttribute("contest", contest);
// check contest permission
UserSecurity userSecurity = context.getUserSecurity();
boolean hasPermisstion = false;
if (level == PermissionLevel.ADMIN) {
hasPermisstion = userSecurity.canAdminContest(contest.getId());
} else if (level == PermissionLevel.PARTICIPATE) {
hasPermisstion = userSecurity.canParticipateContest(contest.getId());
} else if (level == PermissionLevel.VIEW) {
hasPermisstion = userSecurity.canViewContest(contest.getId());
} else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
hasPermisstion = userSecurity.canViewSource(contest.getId());
}
if (!hasPermisstion) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
this.saveErrors(context.getRequest(), messages);
if (isProblemset != null) {
context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
}
return this.handleFailure(mapping, context, messages, "nopermission");
}
// check start time
if (checkStart && !userSecurity.canAdminContest(contest.getId())) {
return this.checkContestStart(mapping, context, contest);
}
return null;
}
use of org.apache.struts.action.ActionMessages in project zoj by licheng.
the class AddProblemAction method execute.
/**
* AddProblemAction.
*
* @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 {
// check contest
boolean isProblemset = context.getRequest().getRequestURI().endsWith("addProblem.do");
ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
if (forward != null) {
return forward;
}
ProblemForm problemForm = (ProblemForm) form;
if (problemForm == null || problemForm.getProblemId() == null) {
return this.handleSuccess(mapping, context);
}
// check title and code
ActionMessages errors = this.validate(problemForm, context);
if (errors.size() > 0) {
return this.handleFailure(mapping, context, errors);
}
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
AbstractContest contest = context.getContest();
Problem problem = problemForm.toProblem();
if (problemForm.isUseContestDefault()) {
problem.getLimit().setId(contest.getLimit().getId());
}
long userId = context.getUserSecurity().getId();
// create problem
problemPersistence.createProblem(problem, userId);
// cprete problem reference, i.e. text, input, output, checker, judge solution, checker source
this.createReference(ReferenceType.DESCRIPTION, problemForm.getDescription(), problem.getId(), userId);
this.createReference(ReferenceType.INPUT, problemForm.getInputData(), problem.getId(), userId);
this.createReference(ReferenceType.OUTPUT, problemForm.getOutputData(), problem.getId(), userId);
this.createReference(ReferenceType.HEADER, problemForm.getChecker(), problem.getId(), userId);
this.createReference(ReferenceType.CHECKER_SOURCE, problemForm.getCheckerSource(), problem.getId(), userId);
this.createReference(ReferenceType.JUDGE_SOLUTION, problemForm.getJudgeSolution(), problem.getId(), userId);
ContestManager.getInstance().refreshContest(problem.getContestId());
return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());
}
use of org.apache.struts.action.ActionMessages in project zoj by licheng.
the class DeleteProblemAction method execute.
/**
* Register.
*
* @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 {
// check problem
boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblem.do");
ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
Problem problem = context.getProblem();
ActionMessages messages = new ActionMessages();
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());
messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));
this.saveErrors(context.getRequest(), messages);
String back = isProblemset ? "showProblems" : "showContestProblems";
context.setAttribute("back", back + ".do?contestId=" + context.getContest().getId());
ContestManager.getInstance().refreshContest(context.getContest().getId());
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionMessages in project zoj by licheng.
the class EditLimitAction method execute.
/**
* Edit Role.
*
* <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 {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
LimitForm limitForm = (LimitForm) form;
if (limitForm.getId() == null || limitForm.getId().trim().length() == 0) {
Limit limit = PersistenceManager.getInstance().getContestPersistence().getDefaultLimit();
limitForm.setId("1");
limitForm.setTimeLimit("" + limit.getTimeLimit());
limitForm.setMemoryLimit("" + limit.getMemoryLimit());
limitForm.setSubmissionLimit("" + limit.getSubmissionLimit());
limitForm.setOutputLimit("" + limit.getOutputLimit());
return this.handleSuccess(mapping, context, "failure");
}
Limit limit = new Limit();
limit.setId(1);
limit.setTimeLimit(Integer.parseInt(limitForm.getTimeLimit()));
limit.setMemoryLimit(Integer.parseInt(limitForm.getMemoryLimit()));
limit.setOutputLimit(Integer.parseInt(limitForm.getOutputLimit()));
limit.setSubmissionLimit(Integer.parseInt(limitForm.getSubmissionLimit()));
PersistenceManager.getInstance().getContestPersistence().updateDefaultLimit(limit);
ActionMessages messages = new ActionMessages();
messages.add("success", new ActionMessage("onlinejudge.DefaultLimit.success"));
this.saveErrors(context.getRequest(), messages);
return this.handleSuccess(mapping, context, "success");
}
Aggregations