|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package com.hzu.bookingsystem.controller;
|
|
|
|
|
|
|
|
|
|
import com.hzu.bookingsystem.VO.ResultVO;
|
|
|
|
|
import com.hzu.bookingsystem.bean.UserAuthBean;
|
|
|
|
|
import com.hzu.bookingsystem.converter.Map2Object;
|
|
|
|
|
import com.hzu.bookingsystem.dto.UserDTO;
|
|
|
|
|
import com.hzu.bookingsystem.bean.UserBean;
|
|
|
|
|
import com.hzu.bookingsystem.service.UserAuthService;
|
|
|
|
|
import com.hzu.bookingsystem.service.UserService;
|
|
|
|
|
import com.hzu.bookingsystem.utils.CookieUtil;
|
|
|
|
|
import com.hzu.bookingsystem.utils.MD5Util;
|
|
|
|
@ -29,21 +31,34 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
public class UserController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserService userService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserAuthService userAuthService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
public ResultVO login(@RequestBody UserBean user,
|
|
|
|
|
public ResultVO login(@RequestBody Map<String, Object> map,
|
|
|
|
|
HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
//0.转换对象
|
|
|
|
|
UserBean user = (UserBean) Map2Object.map2Object(map, UserBean.class);
|
|
|
|
|
String auth = (String) map.get("auth");
|
|
|
|
|
|
|
|
|
|
//1. openid去和数据库里的数据匹配
|
|
|
|
|
UserBean user1 = userService.findByUnameAndPwd(user.getUsername(), user.getPassword());
|
|
|
|
|
System.out.println(user1);
|
|
|
|
|
if (user1 == null) {
|
|
|
|
|
return ResultVOUtil.error(-2, "账号或密码不正确");
|
|
|
|
|
}
|
|
|
|
|
// 判断是否属于该用户组
|
|
|
|
|
UserAuthBean userAuthBean = userAuthService.findByUId(user1.getUId());
|
|
|
|
|
System.out.println(auth);
|
|
|
|
|
System.out.println(userAuthBean);
|
|
|
|
|
if (!userAuthBean.getGroupId().toString().equals(auth)){
|
|
|
|
|
return ResultVOUtil.error(-2, "用户组不匹配");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2. 设置token至redis
|
|
|
|
|
String token = UUID.randomUUID().toString();
|
|
|
|
@ -52,7 +67,7 @@ public class UserController {
|
|
|
|
|
|
|
|
|
|
//3. 设置token至cookie
|
|
|
|
|
CookieUtil.set(response, "token", token, expire);
|
|
|
|
|
return ResultVOUtil.success();
|
|
|
|
|
return ResultVOUtil.success(auth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登出
|
|
|
|
|