LocalLoginController.java
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cn.com.glsx.app.modules;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.com.glsx.app.modules.model.AppUser;
import cn.com.glsx.app.modules.model.LoginByAccountBO;
import cn.com.glsx.app.modules.service.LoginService;
import cn.com.glsx.app.modules.service.UserService;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* 本地登录
*
* @author liuyf
*/
@Slf4j
@Api(value = "登录(本地)", tags = {"登录(本地)"})
@RestController
public class LocalLoginController {
@Autowired
private UserService userService;
@Autowired
private LoginService loginService;
@Autowired
private WxMaService wxMaService;
@GetMapping(value = "/")
public String index() {
return "success";
}
/**
* 本地登录
*/
@ApiOperation(value = "登录系统")
@PostMapping(value = "/login")
public R login(@RequestBody @Validated LoginByAccountBO loginBO) throws WxErrorException {
//本地登录授权
AppUser user = loginService.localAuth(loginBO);
//关联微信账号
loginService.linkWxAuth(loginBO.getCodeForWx(), user);
//创建授权令牌
String token = userService.createToken(user);
Map<String, Object> rtnMap = new HashMap<>();
rtnMap.put("token", token);
rtnMap.put("user", user);
return R.ok().data(rtnMap);
}
@ApiOperation(value = "登出系统")
@GetMapping(value = "/logout")
public R logout() {
//todo 拉黑token
return R.ok();
}
}