⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signupform.java

📁 STRUTS数据库项目开发宝典
💻 JAVA
字号:
package com.relationinfo.webapp.action;import java.io.Serializable;import com.relationinfo.Constants;import com.relationinfo.model.User;import com.relationinfo.service.RoleManager;import com.relationinfo.service.UserExistsException;import com.relationinfo.util.StringUtil;import com.relationinfo.webapp.util.RequestUtil;/** * JSF Page class to handle signing up a new user. * * @author mraible */public class SignupForm extends BasePage implements Serializable {    private User user = new User();    private RoleManager roleManager;    public User getUser() {        return user;    }    public void setUser(User user) {        this.user = user;    }        public void setRoleManager(RoleManager roleManager) {        this.roleManager = roleManager;    }    public String save() throws Exception {                String algorithm =            (String) getConfiguration().get(Constants.ENC_ALGORITHM);        if (algorithm == null) { // should only happen for test case            if (log.isDebugEnabled()) {                log.debug("assuming testcase, setting algorithm to 'SHA'");            }            algorithm = "SHA";        }                user.setPassword(StringUtil.encodePassword(user.getPassword(), algorithm));        user.setEnabled(Boolean.TRUE);                // Set the default user role on this new user        user.addRole(roleManager.getRole(Constants.USER_ROLE));        try {            userManager.saveUser(user);        } catch (UserExistsException e) {            log.warn(e.getMessage());            addMessage("errors.existing.user",                     new Object[] { user.getUsername(), user.getEmail() });            // redisplay the unencrypted passwords            user.setPassword(user.getConfirmPassword());            return null;        }        // Set cookies for auto-magical login ;-)        String loginCookie = userManager.createLoginCookie(user.getUsername());        RequestUtil.setCookie(getResponse(), Constants.LOGIN_COOKIE, loginCookie,                              getRequest().getContextPath());        addMessage("user.registered");        getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);        // Send an account information e-mail        message.setSubject(getText("signup.email.subject"));        sendUserMessage(user, getText("signup.email.message"),                         RequestUtil.getAppURL(getRequest()));                return "mainMenu";    }        public String getCountry() {        return getUser().getAddress().getCountry();    }        // for some reason, the country drop-down won't do     // getUser().getAddress().setCountry(value)    public void setCountry(String country) {        getUser().getAddress().setCountry(country);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -