Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.UserProfile


   */
  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);   
  }
View Full Code Here


     */
    private ActionMessages authenticate(LoginForm form, ContextAdapter context) throws PersistenceException {
        context.getRequest().getSession().invalidate();
        ActionMessages errors = new ActionMessages();
        UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
        UserProfile profile = userPersistence.login(form.getHandle(), form.getPassword());

        // no such user
        if (profile == null) {
            errors.add("password", new ActionMessage("LoginForm.password.invalid"));
            return errors;
        }

        // deactivated
        if (!profile.isActive()) {
            errors.add("password", new ActionMessage("LoginForm.password.deactivated"));
            return errors;
        }

        AuthorizationPersistence authorizationPersistence =
                PersistenceManager.getInstance().getAuthorizationPersistence();

        // get UserSecurity
        UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());

        // get UserPreference
        UserPreference perference = userPersistence.getUserPreference(profile.getId());

        context.setUserProfile(profile);
        context.setUserSecurity(security);
        if(context.getAllCourses().size()!=0) {
          security.setHasCourses(true);
View Full Code Here

     * @return the UserProfile bean.
     * @throws PersistenceException
     *             if failed to convert
     */
    public UserProfile toUserProfile() throws PersistenceException {
        UserProfile profile = new UserProfile();
        if (this.nick != null && this.nick.trim().length() > 0) {
            profile.setNickName(this.nick);
        } else {
            profile.setNickName(this.handle);
        }
        profile.setAddressLine1(this.addressLine1);
        profile.setAddressLine2(this.addressLine2);
        profile.setBirthDate(this.parseDate(this.birthday));
        profile.setCity(this.city);
        profile.setCountry(PersistenceManager.getInstance().getCountry(this.country));
        profile.setEmail(this.email.trim());
        profile.setFirstName(this.firstName.trim());
        profile.setLastName(this.lastName.trim());
        profile.setGender(this.gender.charAt(0));
        profile.setGraduateStudent(this.graduateStudent);
        profile
               .setGraduationYear(this.graduationYear == null || this.graduationYear.trim().length() == 0 ? 0
                                                                                                         : Integer
                                                                                                                  .parseInt(this.graduationYear));
        profile.setHandle(this.handle.trim());
        profile.setMajor(this.major);
        profile.setPhoneNumber(this.phone);
        profile.setSchool(this.school);
        profile.setState(this.state);
        profile.setStudentNumber(this.studentNumber);
        profile.setZipCode(this.zipCode);
        profile.setPassword(this.newPassword);
        return profile;
    }
View Full Code Here

          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");

    }
View Full Code Here

   * Creates a new user profile.
   * @param id the id
   * @return a new user profile instance
   */
  private UserProfile newUserProfile(long id) {
    UserProfile profile = new UserProfile();
    profile.setId(id);
    profile.setHandle("myHandle" + id);
    profile.setPassword("myPassword");
    profile.setEmail("myEmail" + id);
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(new Date(0));
    profile.setGender('M');           
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false)
    return profile;
  }
View Full Code Here

          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 {
          Random ran=new Random();
            submission.setJudgeReply(ran.nextInt()%2==0 ? JudgeReply.WRONG_ANSWER : JudgeReply.ACCEPTED);
            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");

    }
View Full Code Here

     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
        HttpServletResponse response = context.getResponse();

        UserProfile user = context.getUserProfile();
        if (user == null) {
            response.sendError(404);
            return null;
        }

        long id = Utility.parseLong(context.getRequest().getParameter("submissionId"));
        Submission submission = null;
        if (id > 0) {
            submission = PersistenceManager.getInstance().getSubmissionPersistence().getSubmission(id);
        }
        if (submission == null) {
            response.sendError(404);
            return null;
        }
        if (!context.isAdmin() &&
            (submission.getUserProfileId() != user.getId() || !JudgeReply.COMPILATION_ERROR
                                                                                           .equals(submission
                                                                                                             .getJudgeReply()))) {
            response.sendError(404);
            return null;
        }
View Full Code Here

        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);
View Full Code Here

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
      AddUserForm addUserForm = (AddUserForm) form;// TODO Auto-generated method stub
      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);
      }
View Full Code Here

                }
            }
            if (handle != null && password != null) {
                try {
                    UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
                    UserProfile profile = userPersistence.login(handle, password);

                    if (profile != null && profile.isActive()) {

                        AuthorizationPersistence authorizationPersistence =
                                PersistenceManager.getInstance().getAuthorizationPersistence();
                        // get UserSecurity
                        UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());
                        // get UserPreference
                        UserPreference perference = userPersistence.getUserPreference(profile.getId());
                        r.getSession().setAttribute(ContextAdapter.USER_PROFILE_SESSION_KEY, profile);
                        r.getSession().setAttribute(ContextAdapter.SECURITY_SESSION_KEY, security);
                        r.getSession().setAttribute(ContextAdapter.PREFERENCE_SESSION_KEY, perference);
                    } else {
                        Cookie ch = new Cookie("oj_handle", "");
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.UserProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.