a558fb88 by chentao

新增用户注册和登录

1 parent 7204fa59
1 package com.lego.web.controller.core;
2
3 import cn.dev33.satoken.annotation.SaIgnore;
4 import com.lego.common.constant.Constants;
5 import com.lego.common.core.controller.BaseController;
6 import com.lego.common.core.domain.R;
7 import com.lego.common.core.domain.model.LoginBody;
8 import com.lego.common.core.domain.model.RegisterBody;
9 import com.lego.common.enums.UserType;
10 import com.lego.system.service.SysLoginService;
11 import com.lego.system.service.SysRegisterService;
12 import lombok.RequiredArgsConstructor;
13 import org.springframework.validation.annotation.Validated;
14 import org.springframework.web.bind.annotation.PostMapping;
15 import org.springframework.web.bind.annotation.RequestBody;
16 import org.springframework.web.bind.annotation.RequestMapping;
17 import org.springframework.web.bind.annotation.RestController;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 /**
23 * 用户信息
24 *
25 * @author chentao
26 */
27 @Validated
28 @RequiredArgsConstructor
29 @RestController
30 @RequestMapping("/core/user")
31 public class RegisterUserController extends BaseController {
32 private final SysRegisterService registerService;
33 private final SysLoginService loginService;
34 /**
35 * 用户注册
36 */
37 @SaIgnore
38 @PostMapping("/register")
39 public R<Void> register(@Validated @RequestBody RegisterBody user) {
40 user.setUserType(UserType.APP_USER.name());
41 registerService.register(user);
42 return R.ok();
43 }
44
45 @SaIgnore
46 @PostMapping("/login")
47 public R<Map<String, Object>> login(@Validated @RequestBody LoginBody loginBody) {
48 Map<String, Object> ajax = new HashMap<>();
49 // 生成令牌
50 String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
51 loginBody.getUuid());
52 ajax.put(Constants.TOKEN, token);
53 return R.ok(ajax);
54 }
55
56 }
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!