提交 | 用户 | 时间
|
1ac2bc
|
1 |
/** |
懒 |
2 |
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng) |
|
3 |
* <p> |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* <p> |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* <p> |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
package cn.stylefeng.guns.sys.modular.rest.controller; |
|
17 |
|
|
18 |
import cn.stylefeng.guns.base.auth.service.AuthService; |
|
19 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
20 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
21 |
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException; |
|
22 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
23 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
24 |
import io.swagger.annotations.Api; |
|
25 |
import io.swagger.annotations.ApiOperation; |
|
26 |
import org.springframework.stereotype.Controller; |
|
27 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
28 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
29 |
import org.springframework.web.bind.annotation.RequestParam; |
|
30 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
31 |
|
|
32 |
import javax.annotation.Resource; |
|
33 |
|
|
34 |
/** |
|
35 |
* rest方式的登录控制器 |
|
36 |
* |
|
37 |
* @author fengshuonan |
|
38 |
* @Date 2017年1月10日 下午8:25:24 |
|
39 |
*/ |
|
40 |
@Controller |
|
41 |
@RequestMapping("/rest") |
|
42 |
@Api(tags = "系统登录") |
|
43 |
public class RestLoginController extends BaseController { |
|
44 |
|
|
45 |
@Resource |
|
46 |
private AuthService authService; |
|
47 |
|
|
48 |
/** |
|
49 |
* 点击登录执行的动作 |
|
50 |
* |
|
51 |
* @author fengshuonan |
|
52 |
* @Date 2018/12/23 5:42 PM |
|
53 |
*/ |
|
54 |
@RequestMapping(value = "/login", method = RequestMethod.POST) |
|
55 |
@ResponseBody |
|
56 |
@ApiOperation("登录接口") |
|
57 |
public ResponseData restLogin(@RequestParam("username") String username, |
|
58 |
@RequestParam("password") String password) { |
|
59 |
|
|
60 |
if (ToolUtil.isOneEmpty(username, password)) { |
|
61 |
throw new RequestEmptyException("账号或密码为空!"); |
|
62 |
} |
|
63 |
|
|
64 |
//登录并创建token |
|
65 |
String token = authService.login(username, password); |
|
66 |
|
|
67 |
return new SuccessResponseData(token); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* 退出接口 |
|
72 |
* |
|
73 |
* @author fengshuonan |
|
74 |
* @Date 2020/2/16 22:26 |
|
75 |
*/ |
|
76 |
@RequestMapping(value = "/logout", method = RequestMethod.GET) |
|
77 |
@ResponseBody |
|
78 |
@ApiOperation("退出接口") |
|
79 |
public ResponseData logout() { |
|
80 |
authService.logout(); |
|
81 |
return new SuccessResponseData(); |
|
82 |
} |
|
83 |
} |