Search in sources :

Example 21 with UserProfile

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);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile)

Example 22 with UserProfile

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);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile)

Example 23 with UserProfile

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");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) AddUserForm(cn.edu.zju.acm.onlinejudge.form.AddUserForm) Date(java.util.Date) LinkedList(java.util.LinkedList)

Example 24 with UserProfile

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;
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward) RedirectingActionForward(org.apache.struts.action.RedirectingActionForward) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)

Example 25 with UserProfile

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");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward)

Aggregations

UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)32 ActionForward (org.apache.struts.action.ActionForward)9 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)7 ActionMessage (org.apache.struts.action.ActionMessage)6 ActionMessages (org.apache.struts.action.ActionMessages)6 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)3 Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)3 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 List (java.util.List)3