LocalLoginController.java
1.53 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
package cn.com.glsx.app.modules;
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 lombok.extern.slf4j.Slf4j;
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
@RestController
public class LocalLoginController {
@Autowired
private UserService userService;
@Autowired
private LoginService loginService;
@GetMapping(value = "/")
public String index() {
return "success";
}
/**
* 本地登录
*/
@PostMapping(value = "/login")
public R login(@RequestBody @Validated LoginByAccountBO loginBO) {
AppUser user = loginService.localAuth(loginBO);
String token = userService.createToken(user);
Map<String, Object> rtnMap = new HashMap<>();
rtnMap.put("token", token);
rtnMap.put("user", user);
return R.ok().data(rtnMap);
}
@GetMapping(value = "/logout")
public R logout() {
//todo 拉黑token
return R.ok();
}
}