|
|
|
@ -0,0 +1,83 @@
|
|
|
|
|
package com.wsk.controller;
|
|
|
|
|
|
|
|
|
|
import com.wsk.pojo.UserInformation;
|
|
|
|
|
import com.wsk.pojo.UserPassword;
|
|
|
|
|
import com.wsk.response.BaseResponse;
|
|
|
|
|
import com.wsk.service.UserInformationService;
|
|
|
|
|
import com.wsk.service.UserPasswordService;
|
|
|
|
|
import com.wsk.tool.StringUtils;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by wsk1103 on 2017/5/9.
|
|
|
|
|
* 注册中心
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
public class RegisterController {
|
|
|
|
|
@Resource
|
|
|
|
|
private UserPasswordService userPasswordService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private UserInformationService userInformationService;
|
|
|
|
|
|
|
|
|
|
//开始注册用户
|
|
|
|
|
@RequestMapping("/insertUser.do")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public BaseResponse insertUser(HttpServletRequest request,
|
|
|
|
|
@RequestParam String password, @RequestParam String token) {
|
|
|
|
|
//存储与session中的手机号码
|
|
|
|
|
String realPhone = (String) request.getSession().getAttribute("phone");
|
|
|
|
|
//token,唯一标识
|
|
|
|
|
String insertUserToken = (String) request.getSession().getAttribute("token");
|
|
|
|
|
//防止重复提交
|
|
|
|
|
if (StringUtils.getInstance().isNullOrEmpty(insertUserToken) || !insertUserToken.equals(token)) {
|
|
|
|
|
return BaseResponse.fail();
|
|
|
|
|
}
|
|
|
|
|
//该手机号码已经存在
|
|
|
|
|
int uid = userInformationService.selectIdByPhone(realPhone);
|
|
|
|
|
if (uid != 0) {
|
|
|
|
|
return BaseResponse.fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用户信息
|
|
|
|
|
UserInformation userInformation = new UserInformation();
|
|
|
|
|
userInformation.setPhone(realPhone);
|
|
|
|
|
userInformation.setCreatetime(new Date());
|
|
|
|
|
String username = (String) request.getSession().getAttribute("name");
|
|
|
|
|
userInformation.setUsername(username);
|
|
|
|
|
userInformation.setModified(new Date());
|
|
|
|
|
int result;
|
|
|
|
|
result = userInformationService.insertSelective(userInformation);
|
|
|
|
|
//如果用户基本信息写入成功
|
|
|
|
|
if (result == 1) {
|
|
|
|
|
uid = userInformationService.selectIdByPhone(realPhone);
|
|
|
|
|
String newPassword = StringUtils.getInstance().getMD5(password);
|
|
|
|
|
UserPassword userPassword = new UserPassword();
|
|
|
|
|
userPassword.setModified(new Date());
|
|
|
|
|
userPassword.setUid(uid);
|
|
|
|
|
userPassword.setPassword(newPassword);
|
|
|
|
|
result = userPasswordService.insertSelective(userPassword);
|
|
|
|
|
//密码写入失败
|
|
|
|
|
if (result != 1) {
|
|
|
|
|
userInformationService.deleteByPrimaryKey(uid);
|
|
|
|
|
return BaseResponse.fail();
|
|
|
|
|
} else {
|
|
|
|
|
//注册成功
|
|
|
|
|
userInformation = userInformationService.selectByPrimaryKey(uid);
|
|
|
|
|
request.getSession().setAttribute("userInformation", userInformation);
|
|
|
|
|
return BaseResponse.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return BaseResponse.fail();
|
|
|
|
|
}
|
|
|
|
|
}
|