use of cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence 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");
}
use of cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence in project zoj by licheng.
the class ShowRolesAction method execute.
/**
* ShowRolesAction.
*
* @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;
}
AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
List<RoleSecurity> roles = authorizationPersistence.getAllRoles();
context.setAttribute("Roles", roles);
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence in project zoj by licheng.
the class AddRoleAction method execute.
/**
* AddRoleAction.
*
* @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;
}
String name = context.getRequest().getParameter("name");
if (name == null || name.trim().length() == 0) {
return this.handleSuccess(mapping, context, "success");
}
String description = context.getRequest().getParameter("description");
if (description == null) {
description = "";
}
RoleSecurity role = new RoleSecurity(-1, name, description);
AuthorizationPersistence ap = PersistenceManager.getInstance().getAuthorizationPersistence();
ap.createRole(role, context.getUserProfile().getId());
return this.handleSuccess(mapping, context, "success");
}
Aggregations