package act;
import itf.IUserDAO;
import org.apache.log4j.*;
import cls.RegUserDAO;
import mdl.Userinfo;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
/**Registration类
* implements Action
*/
public class Registration extends ActionSupport implements Action {
private Logger log = Logger.getLogger("mdl.Userinfo");
private String reg_username;
private String reg_id;
private String reg_password;
private String result_flg;
private Userinfo userInfo;
private IUserDAO userDAO ;
/**Registration构造函数
*/
public Registration(){}
/**注入userDAO
* @param userDAO userDAO服务对象
*/
public void setUserDAO(IUserDAO userDAO) {
this.userDAO = userDAO;
}
/**注入editUserName
* @param editUserName 名称
*/
public void setEditUserName(String strUserNm) {
this.reg_username = strUserNm;
}
/*
*//**默认执行方法
* @return 字符串
* @throws Exception
*/
public String execute() throws Exception {
return SUCCESS;
}
/**默认执行方法execute(),前执行
* @return 字符串
* @throws Exception
*/
public void validate(){
/* if (reg_username == null||reg_username.equals("")){
reg_username =getText("No Data !");
}*/
}
/**用户注册
* @return 字符串
* @throws Exception
*/
public String regUser() throws Exception {
//检查新注册用户名是否存在
if (this.userDAO.isExist(this.getReg_username()))
{
log.setLevel(Level.WARN);
log.warn("The user instance is found in database");
this.setResult_flg("The user your entered is exist,please input again");
return INPUT;
}
//注册用户登入数据库
log.setLevel(Level.INFO);
log.info("Registration Users instance");
userInfo = new Userinfo();
userInfo.setName(this.getReg_username());
userInfo.setPassword(this.getReg_password());
this.userDAO.insertUser(userInfo);
this.setResult_flg("welcome: " + this.getReg_username() + "登入成功");
return SUCCESS;
}
/**用户Info Display
* @return 字符串
* @throws Exception
*/
public String editUser() throws Exception {
if ( this.getReg_id()==""||this.getReg_id().equals("") ){
return Action.ERROR;
}
userInfo = new Userinfo();
userInfo=this.userDAO.getUser(this.getReg_id());
this.setResult_flg("");
this.setReg_username(userInfo.getName());
this.setReg_password(userInfo.getPassword());
return SUCCESS;
}
/**用户更新
* @return 字符串
* @throws Exception
*/
public String updUser() throws Exception {
//检查注册用户名是否存在
/*if (this.userDAO.isExist(this.getReg_username()))
{
log.setLevel(Level.WARN);
log.warn("The user instance is found in database");
this.setResult_flg("结果: " + this.getReg_username() + "更新失败");
return INPUT;
} */
this.userDAO.deleteUser(this.getReg_id());
userInfo = new Userinfo();
userInfo.setName(this.getReg_username());
userInfo.setPassword(this.getReg_password());
this.userDAO.insertUser(userInfo);
this.setResult_flg("结果: " + this.getReg_username() + "更新成功");
return SUCCESS;
}
/**取得注册用户名
* @return 字符串
*/
public String getReg_username() {
return reg_username;
}
/**设置注册用户名
* @param reg_username 注册用户名
*/
public void setReg_username(String reg_username) {
this.reg_username = reg_username;
}
/**取得注册密码
* @return 字符串
*/
public String getReg_password() {
return reg_password;
}
/**设置注册密码
* @param reg_password 设置注册密码
*/
public void setReg_password(String reg_password) {
this.reg_password = reg_password;
}
/**获取注册返回信息
* @return 字符串
*/
public String getResult_flg() {
return result_flg;
}
/**设置注册用户名
* @param reg_result 设置注册返回信息
*/
public void setResult_flg(String result_flg) {
this.result_flg = result_flg;
}
public String getReg_id() {
return reg_id;
}
public void setReg_id(String reg_id) {
this.reg_id = reg_id;
}
}
- 1
- 2
- 3
前往页