注册用户
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.lovenav.entity.User;
|
||||
import com.lovenav.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.websocket.Session;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@GetMapping("/sendActiveCode")
|
||||
public String sendActiveCode(HttpSession session, User user){
|
||||
String activecode=userService.sendEmailActivecode(user);
|
||||
session.setAttribute("realactivecode",activecode);
|
||||
return "发送验证码成功!";
|
||||
}
|
||||
@RequestMapping("/register")
|
||||
public String userRegister(HttpSession session,User user){
|
||||
|
||||
// 比较验证码
|
||||
if (!user.getActiveCode().equalsIgnoreCase((String) session.getAttribute("realactivecode"))) {
|
||||
return "验证码不正确";
|
||||
}
|
||||
System.out.println(user.getUserLogin());
|
||||
System.out.println(user.getUserEmail());
|
||||
// 用户注册之前根据用户名称查询该用户是否存在如果不存在的情况下才可以注册 如果存在的话就无法注册
|
||||
User user1=userService.selectUserAlreadyExist(user);
|
||||
System.out.println("zhuce");
|
||||
|
||||
if (user1 != null) {
|
||||
return "用户名: " + user1.getUserEmail() + "已被注册!";
|
||||
}
|
||||
//用户数据注册
|
||||
int register = userService.UserRegister(user);
|
||||
if (register <= 0) {
|
||||
// 注册失败了 //转发到错误页面
|
||||
return "注册失败!";
|
||||
}
|
||||
return "注册成功!";
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user