Forráskód Böngészése

密码加密方式修改

黄远 5 éve
szülő
commit
4d917fb062

+ 3 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/LoginController.java

@@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -43,7 +44,7 @@ public class LoginController {
      */
     @PostMapping("/register")
     @ResponseBody
-    public RestResponse register(HttpServletRequest request, UserRequest userRequest){
+    public RestResponse register(HttpServletRequest request, @RequestBody UserRequest userRequest){
         return loginService.register(request, userRequest);
     }
 
@@ -130,7 +131,7 @@ public class LoginController {
             String smsCode = AliyunSmsUtil.sendSmsCode(mobile, AliConstants.SmsConstants.TEST_TEMPLATE_CODE);
             if(StringUtils.isNotBlank(smsCode)){
                 request.getSession().setAttribute(AliConstants.SmsConstants.SMS_CODE_NAME, smsCode);
-                return RestResponse.ok(smsCode, ApiConstants.RESULT_SUCCESS, "发送验证码成功");
+                return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "发送验证码成功");
             }
             return RestResponse.error(ApiConstants.RESULT_ERROR, "手机号不存在,发送验证码失败");
         }

+ 11 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/MTCompanyController.java

@@ -29,4 +29,15 @@ public class MTCompanyController {
     public RestResponse assignRole(MTCompany mtCompany) {
         return mtCompanyUserService.assignRole(mtCompany);
     }
+
+    /**
+     * @description 获取团队成员信息
+     * @date 2019/11/27 10:03 AM
+     * @param mtCompany 公司id
+     * @return
+     */
+    @RequestMapping("/getCompanyMembers")
+    public RestResponse getCompanyUser(MTCompany mtCompany){
+        return mtCompanyUserService.getCompanyMembers(mtCompany);
+    }
 }

+ 8 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IMTCompanyUserService.java

@@ -18,4 +18,12 @@ public interface IMTCompanyUserService extends IService<MTCompanyUser> {
      * @return
      */
     RestResponse assignRole(MTCompany mtCompany);
+
+    /**
+     * @description 获取公司团队信息
+     * @date 2019/11/27 10:03 AM
+     * @param mtCompany:公司id
+     * @return
+     */
+    RestResponse getCompanyMembers(MTCompany mtCompany);
 }

+ 19 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MTCompanyUserService.java

@@ -2,10 +2,14 @@ package cn.com.ty.lift.system.user.service.impl;
 
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.ty.lift.system.user.dao.entity.MTCompanyUser;
+import cn.com.ty.lift.system.user.dao.entity.UserAccount;
 import cn.com.ty.lift.system.user.dao.entity.UserRole;
 import cn.com.ty.lift.system.user.dao.entity.model.MTCompany;
 import cn.com.ty.lift.system.user.dao.mapper.MTCompanyUserMapper;
 import cn.com.ty.lift.system.user.service.IMTCompanyUserService;
+import cn.com.ty.lift.system.user.service.IUserAccountService;
+import cn.com.ty.lift.system.user.service.IUserRoleService;
+import cn.com.ty.lift.system.utils.ProjectUtils;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 /**
  * @author huangyuan
  * @date 2019-12-03
@@ -22,7 +28,10 @@ import org.springframework.transaction.annotation.Transactional;
 public class MTCompanyUserService extends ServiceImpl<MTCompanyUserMapper, MTCompanyUser> implements IMTCompanyUserService {
 
     @Autowired
-    private UserRoleService userRoleService;
+    private IUserRoleService userRoleService;
+
+    @Autowired
+    private IUserAccountService userAccountService;
 
     @Override
     @Transactional
@@ -56,4 +65,13 @@ public class MTCompanyUserService extends ServiceImpl<MTCompanyUserMapper, MTCom
         userRoleService.save(userRole);
         return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "分配角色成功");
     }
+
+    @Override
+    public RestResponse getCompanyMembers(MTCompany mtCompany) {
+        List<MTCompanyUser> mtCompanyUserList = this.list(new QueryWrapper<MTCompanyUser>()
+                .eq("mt_company_id", mtCompany.getCompanyId()));
+        List<String> userIdList = ProjectUtils.getAttrList(mtCompanyUserList, "userId", null);
+        List<UserAccount> userAccountList = (List<UserAccount>) userAccountService.listByIds(userIdList);
+        return RestResponse.ok(userAccountList, ApiConstants.RESULT_SUCCESS, "获取团队用户成功");
+    }
 }

+ 24 - 12
lift-system-service/src/main/java/cn/com/ty/lift/system/utils/PasswordUtils.java

@@ -1,7 +1,8 @@
 package cn.com.ty.lift.system.utils;
 
-import cn.hutool.crypto.SecureUtil;
+import cn.hutool.core.codec.Base64;
 
+import java.security.MessageDigest;
 import java.util.Random;
 
 /**
@@ -12,33 +13,44 @@ import java.util.Random;
 public class PasswordUtils {
 
     /**
-     * @description 生成随机码-盐(salt)
-     * @date 2019/11/27 10:03 AM
      * @param
      * @return 返回随机码
+     * @description 生成随机码-盐(salt)
+     * @date 2019/11/27 10:03 AM
      */
     public static String randomCode() {
         String checkCode = "";
-        char[] character = { '0', '1', '2', '3', '4', '5', '6', '8', '9' };
+        char[] character = {'0', '1', '2', '3', '4', '5', '6', '8', '9'};
         Random random = new Random();
         //生成验证码字符串
-        for (int i = 0; i < 16; i++)
-        {
+        for (int i = 0; i < 16; i++) {
             checkCode += character[random.nextInt(character.length)];
         }
         return checkCode;
     }
 
     /**
-     * @description 对密码进行加盐并进行hash加密
-     * @date 2019/11/27 10:03 AM
      * @param password 密码
-     * @param salt 盐
+     * @param salt     盐
      * @return
+     * @description 对密码进行加盐并进行hash加密
      */
-    public static String generatePassword(String password, String salt){
-        password = String.format(password, salt);
-        return SecureUtil.sha1(password);
+    public static String generatePassword(String password, String salt) {
+        try{
+            String newPassword = password + salt;
+            //sha1加密
+            MessageDigest md = MessageDigest.getInstance("SHA1");
+            //把字符串转为字节数组
+            byte[] bytePassword = newPassword.getBytes();
+            //使用指定的字节来更新我们的摘要
+            md.update(bytePassword);
+            //获取密文  (完成摘要计算)
+            bytePassword = md.digest();
+            return Base64.encode(bytePassword);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+        return "";
     }
 
 }

+ 26 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/utils/ProjectUtils.java

@@ -68,4 +68,30 @@ public class ProjectUtils {
         return map;
     }
 
+    /**
+     *  通过集合对象集合获取对象id集合
+     *@author huangy
+     *@param objList
+     *@param attrName
+     *@param parameterTypes
+     *@return List<? extends Object>
+     *@throws
+     */
+    public static List getAttrList(List objList, String attrName, Class<?>... parameterTypes){
+        List idList = new ArrayList();
+        if(objList != null && objList.size() > 0) {
+            for (Object o: objList) {
+                try {
+                    Class<?> classObj = o.getClass();
+                    Method method = classObj.getMethod(PojoUtils.attrGetMethodName(attrName), parameterTypes);
+                    Object id = method.invoke(o, parameterTypes);
+                    idList.add(id);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return idList;
+    }
+
 }