ApiLoginController.java
1.24 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
package com.gxb.modules.api.controller;
import com.gxb.common.utils.R;
import com.gxb.common.validator.Assert;
import com.gxb.modules.api.annotation.AuthIgnore;
import com.gxb.modules.api.service.TokenService;
import com.gxb.modules.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* API登录授权
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-03-23 15:31
*/
@RestController
@RequestMapping("/api")
public class ApiLoginController {
@Autowired
private UserService userService;
@Autowired
private TokenService tokenService;
/**
* 登录
*/
@AuthIgnore
@PostMapping("login")
public R login(String mobile, String password){
Assert.isBlank(mobile, "手机号不能为空");
Assert.isBlank(password, "密码不能为空");
//用户登录
long userId = userService.login(mobile, password);
//生成token
Map<String, Object> map = tokenService.createToken(userId);
return R.ok(map);
}
}