用户 后端接口 @author @email @date 2021-03-20 11:33:20
| 44 | * @date 2021-03-20 11:33:20 |
| 45 | */ |
| 46 | @RestController |
| 47 | @RequestMapping("/yonghu") |
| 48 | public class YonghuController { |
| 49 | @Autowired |
| 50 | private YonghuService yonghuService; |
| 51 | |
| 52 | @Autowired |
| 53 | private TokenService tokenService; |
| 54 | |
| 55 | /** |
| 56 | * 登录 |
| 57 | */ |
| 58 | @IgnoreAuth |
| 59 | @RequestMapping(value = "/login") |
| 60 | public R login(String username, String password, String captcha, HttpServletRequest request) { |
| 61 | YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username)); |
| 62 | if(user==null || !user.getMima().equals(password)) { |
| 63 | return R.error("账号或密码不正确"); |
| 64 | } |
| 65 | String token = tokenService.generateToken(user.getId(), username,"yonghu", "用户" ); |
| 66 | return R.ok().put("token", token); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 注册 |
| 71 | */ |
| 72 | @IgnoreAuth |
| 73 | @RequestMapping("/register") |
| 74 | public R register(@RequestBody YonghuEntity yonghu){ |
| 75 | //ValidatorUtils.validateEntity(yonghu); |
| 76 | YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao())); |
| 77 | if(user!=null) { |
| 78 | return R.error("注册用户已存在"); |
| 79 | } |
| 80 | Long uId = new Date().getTime(); |
| 81 | yonghu.setId(uId); |
| 82 | yonghuService.insert(yonghu); |
| 83 | return R.ok(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * 退出 |
| 88 | */ |
| 89 | @RequestMapping("/logout") |
| 90 | public R logout(HttpServletRequest request) { |
| 91 | request.getSession().invalidate(); |
| 92 | return R.ok("退出成功"); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * 获取用户的session用户信息 |
| 97 | */ |
| 98 | @RequestMapping("/session") |
| 99 | public R getCurrUser(HttpServletRequest request){ |
| 100 | Long id = (Long)request.getSession().getAttribute("userId"); |
| 101 | YonghuEntity user = yonghuService.selectById(id); |
| 102 | return R.ok().put("data", user); |
| 103 | } |
nothing calls this directly
no outgoing calls
no test coverage detected