use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImplTest method testGetUserProfileByCode.
/**
* Tests getUserProfileByCode method
* @throws Exception to JUnit
*/
public void testGetUserProfileByCode() throws Exception {
String code = "foobar";
persistence.createUserProfile(profile, 1);
persistence.createConfirmCode(profile.getId(), code, 1);
UserProfile profile1 = persistence.getUserProfileByCode(code);
checkUserProfile(profile, profile1);
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImplTest method testGetUserProfile.
/**
* Tests getUserProfile method
* @throws Exception to JUnit
*/
public void testGetUserProfile() throws Exception {
persistence.createUserProfile(profile, 1);
UserProfile profile1 = persistence.getUserProfile(profile.getId());
checkUserProfile(profile, profile1);
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class AddUserAction method execute.
/**
* AddUserRoleAction.
*
* @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 {
// TODO Auto-generated method stub
AddUserForm addUserForm = (AddUserForm) form;
boolean isTeacher = context.getRequest().getRequestURI().endsWith("addTeacher.do");
UserProfile u = context.getUserProfile();
long teacherId = u.getId();
UserProfile student = PersistenceManager.getInstance().getUserPersistence().getUserProfileByHandle(addUserForm.getUsername());
if (student == null) {
student = new UserProfile();
student.setAddressLine1("line1");
student.setAddressLine2("line2");
student.setHandle(addUserForm.getUsername());
student.setPassword(addUserForm.getPassword());
student.setFirstName(addUserForm.getUsername());
student.setLastName("");
student.setEmail(new Integer(new Date().hashCode()).toString());
student.setCity("null");
student.setState("null");
student.setBirthDate(new Date());
student.setCountry(PersistenceManager.getInstance().getCountry("44"));
student.setZipCode("null");
student.setPhoneNumber("null");
student.setGender('M');
student.setSchool("Zhejiang University");
student.setMajor("null");
student.setGraduateStudent(false);
student.setGraduationYear(2010);
student.setStudentNumber("0000");
student.setConfirmed(true);
if (!isTeacher) {
PersistenceManager.getInstance().getUserPersistence().createUserProfile(student, teacherId);
} else {
PersistenceManager.getInstance().getUserPersistence().createTeacher(student, teacherId);
}
}
List<String> list = new LinkedList<String>();
list.add(addUserForm.getUsername());
if (!isTeacher) {
PersistenceManager.getInstance().getAuthorizationPersistence().addRoleUsers(list, 10);
} else {
PersistenceManager.getInstance().getAuthorizationPersistence().addRoleUsers(list, 11);
}
return handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class BaseAction method execute.
/**
* This is where the action processes the request. It forwards the invocation to the abstract execute() method and
* returns its forward. Unexcepted exceptions are handled.
*
* @param mapping
* the action mapping that holds the forwards.
* @param form
* the form bean for input.
* @param request
* the http servlet request.
* @param response
* the http servlet response.
*
* @return an action forward or null if the response is committed.
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
UserProfile user = (UserProfile) request.getSession().getAttribute(ContextAdapter.USER_PROFILE_SESSION_KEY);
long actionId = PerformanceManager.getInstance().actionStart(this, request, user);
ContextAdapter context = null;
ActionForward forward = null;
try {
context = new ContextAdapter(request, response);
this.info(this.makeInfo(BaseAction.ENTER_OP, context.getOperator(), null, request));
// log parameters with debug level
/*
* debug("Received parameters:"); for (Enumeration enu = request.getParameterNames();
* enu.hasMoreElements();) { String name = (String) enu.nextElement(); debug("[" + name + "]"); for (int i =
* 0; i < request.getParameterValues(name).length; ++i) { debug(" [" + request.getParameterValues(name)[i]
* + "]"); } }
*/
forward = this.execute(mapping, form, context);
} catch (Exception e) {
this.error(e);
forward = this.handleFailure(mapping, context, BaseAction.GENERIC_ERROR_RESOURCE_KEY);
}
PerformanceManager.getInstance().actionEnd(actionId);
return forward;
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class ShowUserRoleAction 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 {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
UserProfile user = UserManager.getInstance().getUserProfile(userId);
if (user == null) {
return this.handleSuccess(mapping, context, "failure");
}
context.getRequest().setAttribute("User", user);
context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
context.getRequest().setAttribute("UserRoles", PersistenceManager.getInstance().getAuthorizationPersistence().getUserSecurity(userId).getRoles());
return this.handleSuccess(mapping, context, "success");
}
Aggregations