Package cn.edu.zju.acm.onlinejudge.persistence

Examples of cn.edu.zju.acm.onlinejudge.persistence.UserPersistence


        }

        if (!this.isLogin(context)) {
            return this.handleSuccess(mapping, context, "login");
        }
        UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
        ProfileForm profileForm = (ProfileForm) form;
        UserProfile profile = context.getUserProfile();
        UserPreference perference = userPersistence.getUserPreference(profile.getId());
        if (profileForm.getHandle() == null) {
            profileForm.populate(profile, perference);
            context.setAttribute("ProfileForm", profileForm);
            return this.handleSuccess(mapping, context, "failure");
        }

        if (userPersistence.login(profileForm.getHandle(), profileForm.getPassword()) == null) {
            return this.handleFailure(mapping, context, "password", "ProfileForm.password.invalid");
        }

        UserProfile newProfile = profileForm.toUserProfile();
        newProfile.setId(profile.getId());
        newProfile.setRegDate(profile.getRegDate());

        if (!profile.getHandle().equals(newProfile.getHandle())) {
            return this.handleFailure(mapping, context, "handle", "ProfileForm.handle.changed");
        }

        if (!profile.getEmail().equals(newProfile.getEmail())) {
            UserProfile temp = userPersistence.getUserProfileByEmail(newProfile.getEmail());
            if (temp != null && temp.getId() != profile.getId()) {
                return this.handleFailure(mapping, context, "email", "ProfileForm.email.used");
            }
        }

        userPersistence.updateUserProfile(newProfile, profile.getId());
        UserPreference newPerference = profileForm.toUserPreference();
        newPerference.setId(profile.getId());
        userPersistence.updateUserPreference(newPerference, profile.getId());
        context.setUserProfile(newProfile);
        context.getRequest().setAttribute("Countries",
                                          PersistenceManager.getInstance().getUserPersistence().getAllCountries());

        ActionMessages messages = new ActionMessages();
View Full Code Here


        String handle = context.getRequest().getParameter("handle");
        String email = context.getRequest().getParameter("email");
        if ((handle == null || handle.trim().length() == 0) && (email == null || email.trim().length() == 0)) {
          return this.handleSuccess(mapping, context, "success");
        }
        UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
        UserProfile user = null;
       
       
        if (handle != null && handle.trim().length() > 0) {
          user = userPersistence.getUserProfileByHandle(handle);
        }
        if (user == null) {
          if (email != null && email.trim().length() > 0) {
              user = userPersistence.getUserProfileByEmail(email.trim());
          }
        }
       
        if (user != null) {
          forgotPassword(user, context);
View Full Code Here

       
    }

    public void forgotPassword(UserProfile user, ContextAdapter context) throws Exception {
      UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
        String code = RandomStringGenerator.generate();
        userPersistence.createConfirmCode(user.getId(), code, user.getId());

        String url =
                ConfigManager.getValue("home_url") + context.getRequest().getContextPath() + "/resetPassword.do?code=" +
                    code;
        EmailService.sendPasswordEmail(user, url);
View Full Code Here

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

    public UserProfile getUserProfile(long userId) throws PersistenceException {
        Object key = new Long(userId);
        synchronized (this.userCache) {
            UserProfile user = this.userCache.get(key);
            if (user == null) {
                UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
                user = userPersistence.getUserProfile(userId);
                this.userCache.put(key, user);
            }
            return user;
        }
    }
View Full Code Here

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

     * @throws Exception
     */
    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

                    }
                }
            }
            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.persistence.UserPersistence

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.