Browse Source

登录拆分接口

zhoutg 6 years ago
parent
commit
ada3d82541

+ 1 - 1
user-service/src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -25,7 +25,7 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
         http
                 .csrf().disable()
                 .authorizeRequests()
-                .regexMatchers(".*swagger.*", ".*v2.*", ".*webjars.*", "/user/login.*", "/user/registry.*", "/user/test.*", "/druid.*", "/actuator.*", "/hystrix.*", "/hi.*", "/test.*").permitAll()
+                .regexMatchers(".*swagger.*", ".*v2.*", ".*webjars.*", "/user/getJwt.*", "/user/registry.*", "/user/test.*", "/druid.*", "/actuator.*", "/hystrix.*", "/hi.*", "/test.*").permitAll()
                 .antMatchers("/userver/getImgVerification").permitAll()
                 .antMatchers("/userver/verifyImgVerification").permitAll()
                 .antMatchers("/userver/getSmsWithRegister").permitAll()

+ 1 - 1
user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -31,7 +31,7 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
                     || matchers("/swagger-ui.html/**", request)
                     || matchers("/swagger-resources/**", request)
                     || matchers("/webjars/**", request)
-                    || matchers("/user/login/**", request)
+                    || matchers("/user/getJwt/**", request)
                     || matchers("/user/registry/**", request)
                     || matchers("/user/test/**", request)
                     || matchers("/druid/**", request)

+ 16 - 0
user-service/src/main/java/com/diagbot/dto/JwtDTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description: jwt 输出类
+ * @author: gaodm
+ * @time: 2018/8/2 14:22
+ */
+@Getter
+@Setter
+public class JwtDTO {
+    private String token;
+    private Integer type;
+}

+ 0 - 2
user-service/src/main/java/com/diagbot/dto/LoginDTO.java

@@ -1,7 +1,6 @@
 package com.diagbot.dto;
 
 import com.diagbot.entity.Organization;
-import com.diagbot.entity.User;
 import com.diagbot.entity.wrapper.MenuWrapper;
 import lombok.Getter;
 import lombok.Setter;
@@ -17,7 +16,6 @@ import java.util.List;
 @Setter
 public class LoginDTO {
     private UserLoginDTO userLoginDTO;
-    private String token;
     private Organization organization;
     private List<MenuWrapper> menuWrappers;
 }

+ 44 - 26
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.client.AuthServiceClient;
 import com.diagbot.client.DiagbotmanClient;
 import com.diagbot.dto.GetConsoleUserInfoDTO;
+import com.diagbot.dto.JwtDTO;
 import com.diagbot.dto.LoginDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.UserAndProdutUDTO;
@@ -219,11 +220,46 @@ public class UserFacade extends UserServiceImpl {
     /**
      * 登录
      *
+     * @return 登录相关信息
+     */
+    public LoginDTO getUserOrgMenu() {
+        LoginDTO data = new LoginDTO();
+
+        Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+        User user = this.getById(userId);
+        if (user == null) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "用户不存在【" + userId + "】");
+        }
+        //添加用户
+        UserLoginDTO userLoginDTO = new UserLoginDTO();
+        BeanUtil.copyProperties(user, userLoginDTO);
+        data.setUserLoginDTO(userLoginDTO);
+
+        //添加机构信息
+        Organization org = organizationFacade.getById(user.getId());
+        data.setOrganization(org);
+        //添加菜单信息
+        List<MenuWrapper> menuList = menuFacade.getByRole(user.getId());
+        Map<Long, List<MenuWrapper>> menuMap = EntityUtil.makeEntityListMap(menuList, "parentId");
+        List<MenuWrapper> menuRes = menuMap.get(-1L);
+        for(MenuWrapper bean : menuRes) {
+            getSonMenu(bean, menuMap);
+        }
+        data.setMenuWrappers(menuRes);
+        return data;
+    }
+
+
+    /**
+     * 获取jwt
+     *
      * @param username 用户名
      * @param password 密码
-     * @return 登录相关信息
+     * @return jwt
      */
-    public RespDTO login(String username, String password) {
+    public JwtDTO  getJwt(String username, String password) {
+        JwtDTO data = new JwtDTO();
         if (StringUtil.isBlank(username)) {
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "请输入手机号!");
@@ -241,29 +277,9 @@ public class UserFacade extends UserServiceImpl {
             throw new CommonException(ServiceErrorCode.USER_PASSWORD_ERROR);
         }
         JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2", "password", username, password);
-        // 获得用户菜单
-        if (null == jwt) {
-            throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
-        }
-        LoginDTO loginDTO = new LoginDTO();
-        //添加用户
-        UserLoginDTO userLoginDTO = new UserLoginDTO();
-        BeanUtil.copyProperties(user, userLoginDTO);
-        loginDTO.setUserLoginDTO(userLoginDTO);
-        //添加token
-        loginDTO.setToken(jwt.getAccess_token());
-        //添加机构信息
-        Organization org = organizationFacade.getById(user.getId());
-        loginDTO.setOrganization(org);
-        //添加菜单信息
-        List<MenuWrapper> menuList = menuFacade.getByRole(user.getId());
-        Map<Long, List<MenuWrapper>> menuMap = EntityUtil.makeEntityListMap(menuList, "parentId");
-        List<MenuWrapper> menuRes = menuMap.get(-1L);
-        for(MenuWrapper bean : menuRes) {
-            getSonMenu(bean, menuMap);
-        }
-        loginDTO.setMenuWrappers(menuRes);
-        return RespDTO.onSuc(loginDTO);
+        data.setToken(jwt.getAccess_token());
+        data.setType(user.getType());
+        return data;
     }
 
 
@@ -682,8 +698,10 @@ public class UserFacade extends UserServiceImpl {
         return RespDTO.onSuc("绑定成功");
     }
 
+
     /**
-     * @param userId
+     * 删除用户信息和机构信息
+     * @param baseIdVO 参数
      * @return 删除用户信息和机构信息
      */
     public RespDTO<Boolean> updateDeleteds(BaseIdVO baseIdVO) {

+ 17 - 5
user-service/src/main/java/com/diagbot/web/UserController.java

@@ -3,6 +3,7 @@ package com.diagbot.web;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.GetConsoleUserInfoDTO;
+import com.diagbot.dto.JwtDTO;
 import com.diagbot.dto.LoginDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.UserOrgDTO;
@@ -65,13 +66,24 @@ public class UserController {
     }
 
 
-    @ApiOperation(value = "登录[by:zhoutg]",
+    @ApiOperation(value = "登录获取jwt[by:zhoutg]",
             notes = "username:用户名,必填<br>" +
                     "password:密码, 必填<br> ")
-    @PostMapping("/login")
-    @SysLogger("login")
-    public RespDTO<LoginDTO> login(@RequestBody UserLoginVO userLoginVO) {
-        return userFacade.login(userLoginVO.getUsername(), userLoginVO.getPassword());
+    @PostMapping("/getJwt")
+    @SysLogger("getJwt")
+    public RespDTO<JwtDTO> getJwt(@RequestBody UserLoginVO userLoginVO) {
+        JwtDTO data = userFacade.getJwt(userLoginVO.getUsername(), userLoginVO.getPassword());
+        return RespDTO.onSuc(data);
+    }
+
+
+    @ApiOperation(value = "获取用户、机构、菜单信息[by:zhoutg]",
+            notes = "")
+    @PostMapping("/getUserOrgMenu")
+    @SysLogger("getUserOrgMenu")
+    public RespDTO<LoginDTO> getUserOrgMenu() {
+        LoginDTO data = userFacade.getUserOrgMenu();
+        return RespDTO.onSuc(data);
     }