| | |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.crypto.symmetric.AES; |
| | | import com.yuanchu.limslaboratory.mapper.RoleManageMapper; |
| | | import com.yuanchu.limslaboratory.mapper.UserMapper; |
| | | import com.yuanchu.limslaboratory.pojo.Menu; |
| | | import com.yuanchu.limslaboratory.pojo.RoleMenu; |
| | | import com.yuanchu.limslaboratory.pojo.User; |
| | | import com.yuanchu.limslaboratory.pojo.dto.RoleAndMenuDto; |
| | | import com.yuanchu.limslaboratory.shiro.utils.JwtUtils; |
| | | import com.yuanchu.limslaboratory.utils.MyUtil; |
| | | import com.yuanchu.limslaboratory.utils.RedisUtil; |
| | | import com.yuanchu.limslaboratory.vo.Result; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class UserLoginUtils { |
| | | |
| | | @Resource |
| | | private UserClient userClient; |
| | | |
| | | @Value("${login.userID}") |
| | | private String LoginUserID; |
| | | |
| | | @Value("${login.secret}") |
| | | private String LoginSecret; |
| | | |
| | | @Autowired |
| | | private JwtUtils jwtUtils; |
| | | |
| | | |
| | | public Result<Map<String, Object>> LoginExamine(User user){ |
| | | Map<String, Object> mapData = new HashMap<>(); |
| | | mapData.put("LoginUserID", LoginUserID); |
| | | mapData.put("LoginSecret", LoginSecret); |
| | | Result<?> code = userClient.BusynessUserLogin(mapData); |
| | | if (code.getCode() == 200){ |
| | | Result<?> result = userClient.BusynessUserLoginToken(code.getData().toString()); |
| | | if (result.getCode() == 200){ |
| | | Map data = (Map) result.getData(); |
| | | String token = data.get("token").toString(); |
| | | data.remove("token"); |
| | | HashMap<String, Object> mapRedis = new HashMap<>(); |
| | | mapRedis.put("id", user.getId()); |
| | | mapRedis.put("account", user.getAccount()); |
| | | mapRedis.put("name", user.getName()); |
| | | mapRedis.put("enterpriseId", user.getEnterpriseId()); |
| | | mapRedis.put("data", data); |
| | | String adminMD5 = SecureUtil.md5(SecureUtil.md5(user.getAccount())); |
| | | // 构建 |
| | | AES aes = SecureUtil.aes(adminMD5.getBytes(StandardCharsets.UTF_8)); |
| | | String admins = aes.encryptHex(user.getAccount()); |
| | | mapRedis.put("sessionLayerId", SecureUtil.md5(admins)); |
| | | mapRedis.put("roleId",user.getRoleId()); |
| | | //存入redis,二个小时后删除 |
| | | RedisUtil.set(token, mapRedis, 120); |
| | | // |
| | | RedisUtil.set("access_token",token,120); |
| | | // 将签发的 JWT token 返回给前端 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | String refresh = JwtUtils.sign(user.getAccount()); |
| | | map.put("token", token); |
| | | map.put("refresh", refresh); |
| | | RedisUtil.set(user.getAccount(), map, 168); |
| | | return Result.success(map); |
| | | } else { |
| | | return Result.fail(result.getMessage()); |
| | | } |
| | | } else { |
| | | return Result.fail(code.getMessage()); |
| | | } |
| | | String token = JwtUtils.sign(user.getAccount()); |
| | | HashMap<String, Object> mapRedis = new HashMap<>(); |
| | | mapRedis.put("id", user.getId()); |
| | | mapRedis.put("account", user.getAccount()); |
| | | mapRedis.put("name", user.getName()); |
| | | mapRedis.put("enterpriseId", user.getEnterpriseId()); |
| | | |
| | | |
| | | String adminMD5 = SecureUtil.md5(SecureUtil.md5(user.getAccount())); |
| | | // 构建 |
| | | AES aes = SecureUtil.aes(adminMD5.getBytes(StandardCharsets.UTF_8)); |
| | | String admins = aes.encryptHex(user.getAccount()); |
| | | mapRedis.put("sessionLayerId", SecureUtil.md5(admins)); |
| | | mapRedis.put("roleId",user.getRoleId()); |
| | | |
| | | //存入redis,二个小时后删除 |
| | | RedisUtil.set(token, mapRedis, 120); |
| | | // |
| | | RedisUtil.set("access_token",token,120); |
| | | // 将签发的 JWT token 返回给前端 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | String refresh = JwtUtils.sign(user.getAccount()); |
| | | map.put("token", token); |
| | | map.put("refresh", refresh); |
| | | RedisUtil.set(user.getAccount(), map, 168); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | } |