use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class SubmitAction method execute.
/**
* SubmitAction.
*
* @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 (!this.isLogin(context, true)) {
return this.handleSuccess(mapping, context, "login");
}
boolean isProblemset = context.getRequest().getRequestURI().endsWith("submit.do");
ActionForward forward = this.checkProblemParticipatePermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
Problem problem = context.getProblem();
long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
if (language == null) {
return this.handleSuccess(mapping, context, "submit");
}
String source = context.getRequest().getParameter("source");
if (source == null || source.length() == 0) {
return this.handleSuccess(mapping, context, "submit");
}
List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
if (refrance.size() != 0) {
Reference r = (Reference) refrance.get(0);
String percode = new String(r.getContent());
source = percode + "\n" + source;
}
UserProfile user = context.getUserProfile();
if (submitCache != null && submitCache.contains(user.getId())) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("source", source);
return handleSuccess(mapping, context, "submit");
}
if (contest.isCheckIp()) {
forward = this.checkLastLoginIP(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
}
Submission submission = new Submission();
submission.setContestId(contest.getId());
submission.setLanguage(language);
submission.setProblemId(problem.getId());
submission.setUserProfileId(user.getId());
submission.setContent(source);
submission.setMemoryConsumption(0);
submission.setTimeConsumption(0);
submission.setSubmitDate(new Date());
SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();
if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
submissionPersistence.createSubmission(submission, user.getId());
} else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
submissionPersistence.createSubmission(submission, user.getId());
} else {
submission.setJudgeReply(JudgeReply.QUEUING);
submissionPersistence.createSubmission(submission, user.getId());
JudgeService.getInstance().judge(submission, Priority.NORMAL);
}
context.setAttribute("contestOrder", submission.getContestOrder());
if (submitCache != null) {
submitCache.put(user.getId(), user.getId());
}
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserSearchAction method execute.
/**
* ShowRunsAction.
*
* @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 {
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
context.setAttribute("UserSearchForm", form);
context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
UserSearchForm userForm = (UserSearchForm) form;
if (this.empty(userForm.getCountryId()) && this.empty(userForm.getEmail()) && this.empty(userForm.getFirstName()) && this.empty(userForm.getHandle()) && this.empty(userForm.getLastName()) && this.empty(userForm.getRoleId()) && this.empty(userForm.getSchool())) {
return this.handleSuccess(mapping, context, "success");
}
UserCriteria criteria = userForm.toUserCriteria();
String export = context.getRequest().getParameter("exportFormat");
if ("txt".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
} else if ("xls".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
}
long paging = Utility.parseLong(userForm.getPaging(), 10, 50);
;
long usersNumber = PersistenceManager.getInstance().getUserPersistence().searchUserProfilesCount(criteria);
if (usersNumber == 0) {
context.setAttribute("users", new ArrayList<UserProfile>());
context.setAttribute("pageNumber", new Long(0));
context.setAttribute("totalPages", new Long(0));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(0));
return this.handleSuccess(mapping, context, "success");
}
long totalPages = (usersNumber - 1) / paging + 1;
long pageNumber = Utility.parseLong(userForm.getPageNumber(), 1, totalPages);
long startIndex = paging * (pageNumber - 1);
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, (int) startIndex, (int) paging);
context.setAttribute("users", users);
context.setAttribute("pageNumber", new Long(pageNumber));
context.setAttribute("totalPages", new Long(totalPages));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(usersNumber));
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile 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");
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class DeleteUserRoleAction method execute.
/**
* DeleteUserRoleAction.
*
* @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;
}
long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
long roleId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("roleId")));
UserProfile user = UserManager.getInstance().getUserProfile(userId);
if (user == null) {
return this.handleSuccess(mapping, context, "failure");
}
PersistenceManager.getInstance().getAuthorizationPersistence().deleteUserRole(userId, roleId);
return this.handleSuccess(mapping, context, "success", "?userId=" + userId);
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class RegisterAction 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 {
if (!Features.register()) {
context.getResponse().sendError(404);
return null;
}
UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
ProfileForm profileForm = (ProfileForm) form;
if (profileForm.getHandle() == null) {
return this.handleSuccess(mapping, context, "failure");
}
context.getRequest().getSession().invalidate();
ActionMessages errors = this.validate(userPersistence, profileForm);
if (errors.size() > 0) {
return this.handleFailure(mapping, context, errors);
}
// create user profile
UserProfile profile = profileForm.toUserProfile();
userPersistence.createUserProfile(profile, 0);
// create user perference
UserPreference perference = profileForm.toUserPreference();
perference.setId(profile.getId());
userPersistence.createUserPreference(perference, 0);
AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
authorizationPersistence.addUserRole(profile.getId(), 2);
context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
// get UserSecurity
UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());
context.setUserProfile(profile);
context.setUserSecurity(security);
context.setUserPreference(perference);
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.register.success"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "");
return this.handleSuccess(mapping, context, "success");
}
Aggregations