package com.bicycle.action.user;
import java.util.regex.Pattern;
import com.bicycle.bean.BicycleUser;
import com.bicycle.bean.Consumer;
import com.bicycle.server.RegisteredServer;
import com.opensymphony.xwork2.ActionSupport;
public class RegisteredAction extends ActionSupport {
/**
* 用户注册的action
* */
private String password;
private String pwd;
private Consumer consumer;
private BicycleUser bicycleUser;
private RegisteredServer registerdServer;
private static long maxPhone = 20000000000L;
private static long minPhone = 10000000000L;
private static long maxQQ = 200000000000L;
private static long minQQ = 10000;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Consumer getConsumer() {
return consumer;
}
public void setConsumer(Consumer consumer) {
this.consumer = consumer;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public BicycleUser getBicycleUser() {
return bicycleUser;
}
public void setBicycleUser(BicycleUser bicycleUser) {
this.bicycleUser = bicycleUser;
}
public RegisteredServer getRegisterdServer() {
return registerdServer;
}
public void setRegisterdServer(RegisteredServer registerdServer) {
this.registerdServer = registerdServer;
}
public String execute() throws Exception {
if(this.consumer.getName().equals("") || this.consumer.getEmail().equals("") || this.consumer.getPhone().equals("") || this.consumer.getQq().equals("")) {
System.out.println("注册资料不全");
this.addFieldError("error", "请补全注册信息");
return ERROR;
}else if(!Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*").matcher(this.consumer.getEmail()).matches()) {
System.out.println("邮箱格式不正确");
this.addFieldError("error", "邮箱格式不正确");
return ERROR;
}else if(this.consumer.getQq() < minQQ || this.consumer.getQq() > maxQQ) {
System.out.println("QQ号码不正确");
this.addFieldError("error", "QQ号码应为5-11位数字");
return ERROR;
}else if(this.consumer.getPhone() < minPhone || this.consumer.getPhone() > maxPhone) {
System.out.println("电话号码不正确");
this.addFieldError("error", "电话号码应为11位数字");
return ERROR;
}else if(!this.getPwd().equals(this.getPassword())) {
System.out.println("密码确认错误");
this.addFieldError("error", "密码确认不正确");
return ERROR;
}else {
this.bicycleUser = new BicycleUser();
this.bicycleUser.setName(this.consumer.getUserName());
this.bicycleUser.setPwd(this.getPwd());
this.bicycleUser.setStatus(0);
this.registerdServer.addUser(consumer, bicycleUser);
return SUCCESS;
}
}
}
- 1
- 2
前往页