CeDo
2021-05-25 fe467f6c6be0b8b1cc47d2cdef66503fcfc59e7d
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
package com.panzhihua.grid_app.api;
 
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.vos.LoginReturnVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.service.auth.TokenService;
import com.panzhihua.grid_app.model.vos.LoginBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * @author cedoo
 */
@RestController
@RequestMapping("/")
@Api(tags = {"网格综治APP登录模块"})
public class LoginApi extends BaseController {
    @Resource
    private TokenService tokenService;
 
    @ApiOperation(value = "网格综治APP登录",response = LoginReturnVO.class)
    @PostMapping("login")
    public R login(@RequestBody LoginBody loginBody){
        String account = loginBody.getAccount();
        String password = loginBody.getPassword();
        boolean empty = ObjectUtils.isEmpty(account);
        boolean empty1 = ObjectUtils.isEmpty(password);
        if (empty||empty1) {
            return R.fail("账户密码不能为空");
        }
        R r = tokenService.loginGridApp(account, password);
        return r;
    }
 
    @ApiOperation(value = "刷新token",response =LoginReturnVO.class)
    @GetMapping("refreshToken")
    @ApiImplicitParam(name ="refreshToken",value = "登录返回的刷新token")
    public R refreshToken(@RequestParam("refreshToken")String refreshToken){
        return tokenService.refreshToken(refreshToken);
    }
 
    @ApiOperation(value = "用户登出")
    @PostMapping("logout")
    public R logout(){
        String token = this.getToken();
        boolean empty2 = ObjectUtils.isEmpty(token);
        if (empty2) {
            return R.ok();
        }
        return tokenService.logout(token);
    }
 
 
}