提交 4ed048d3 编写于 作者: 爱吃血肠's avatar 爱吃血肠

...

上级 203168f3
package com.yingjun.ssm.service; package com.yingjun.ssm.service;
import java.util.List; import java.util.List;
import com.yingjun.ssm.entity.User; import com.yingjun.ssm.entity.User;
import javax.servlet.http.HttpSession;
/** /**
* @author liyunfeng * @author liyunfeng
* 增加必要注释 * 增加必要注释
...@@ -77,5 +80,5 @@ public interface UserService { ...@@ -77,5 +80,5 @@ public interface UserService {
* 处理用户注册 * 处理用户注册
* @param user * @param user
*/ */
public void userRegister(User user); public void userRegister(User user, String code, HttpSession session);
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory; ...@@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
/** /**
* @author liyunfeng * @author liyunfeng
* 普通用户 * 普通用户
...@@ -86,8 +88,22 @@ public class UserServiceImpl implements UserService { ...@@ -86,8 +88,22 @@ public class UserServiceImpl implements UserService {
* @param user * @param user
*/ */
@Override @Override
public void userRegister(User user) { public void userRegister(User user, String code,HttpSession session) {
try{
String emailCode = (String)session.getAttribute("code");
if(!emailCode.equals(code)){
throw new BizException("验证码错误");
}
if(1 == userDao.insertTUser(user)){
throw new Exception("插入数据影响函数不唯一");
}
}catch (BizException biz){
LOG.error("验证码错误",biz);
throw new BizException("验证码错误");
}catch (Exception e){
LOG.error("插入数据影响函数不唯一",e);
throw new BizException("插入数据影响函数不唯一");
}
} }
public UserDao getTUserDao() { public UserDao getTUserDao() {
......
...@@ -73,9 +73,9 @@ public class UserController { ...@@ -73,9 +73,9 @@ public class UserController {
*/ */
@ResponseBody @ResponseBody
@RequestMapping(value = "/register",produces = {"application/json;charset=UTF-8"}) @RequestMapping(value = "/register",produces = {"application/json;charset=UTF-8"})
public BaseResult<Object> register(User user) { public BaseResult<Object> register(User user,String code,HttpSession session) {
try { try {
userService.userRegister(user); userService.userRegister(user,code,session);
} catch (BizException e) { } catch (BizException e) {
return new BaseResult<>(false, e.getMessage()); return new BaseResult<>(false, e.getMessage());
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册