songhuangfeng123
2022-09-02 fabd08d87d00bfdf1aacf473fd905fdd3c903ed3
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
package com.gkhy.safePlatform.accountController;
 
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.MenuRPCRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserLoginRPCRespDTO;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.security.Principal;
import java.util.List;
 
@RestController
@RequestMapping("/auth")
public class LoginController {
 
    @DubboReference(check = false)
    private AccountAuthService accountAuthService;
 
    @RequestMapping("/login")
    public ResultVO<UserLoginRPCRespDTO> authLogin(@RequestBody JSONObject loginForm){
        String username = loginForm.getString("username");
        String password = loginForm.getString("password");
        return accountAuthService.authLogin(username, password);
    }
 
    @RequestMapping("/menu")
    public ResultVO<List<MenuRPCRespDTO>> getMenu(Authentication authentication, Long projectId){
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountAuthService.getMenu(currentUser, projectId);
    }
}