jiangqs
2023-04-20 437a8ae4bcca79e8886662a40c11f499fea1a25e
hrt-auth/src/main/java/com/hrt/auth/service/SysLoginService.java
@@ -1,5 +1,7 @@
package com.hrt.auth.service;
import com.hrt.system.api.model.AppMiniLoginDto;
import com.hrt.system.api.model.AppMiniLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.hrt.common.core.constant.CacheConstants;
@@ -101,6 +103,41 @@
        return userInfo;
    }
    /**
     * 登录
     */
    public AppMiniLoginVo miniLogin(AppMiniLoginDto appMiniLoginDto)
    {
        // 查询用户信息
        R<AppMiniLoginVo> userResult = remoteUserService.miniLogin(appMiniLoginDto);
        if (R.FAIL == userResult.getCode())
        {
            throw new ServiceException(userResult.getMsg());
        }
        AppMiniLoginVo userInfo = userResult.getData();
        SysUser user = userResult.getData().getSysUser();
        String username = user.getUserName();
        // IP黑名单校验
        String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
        if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
        {
            recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
            throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
        }
        if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
        {
            recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
            throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
        }
        if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
        {
            recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
        }
        recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
        return userInfo;
    }
    public void logout(String loginName)
    {
        recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");