jiangping
2025-02-08 75ac3d5acdd448f063a3c307b4c733e37b4fc04f
server/service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java
@@ -3,6 +3,7 @@
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.system.dto.LoginDTO;
import com.doumee.dao.system.model.SystemLoginLog;
@@ -20,6 +21,7 @@
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Objects;
@Slf4j
@Service
@@ -49,16 +51,18 @@
        loginLog.setOsInfo(Utils.User_Client.getOS(request));
        loginLog.setServerIp(Utils.Server.getIP());
        // 校验验证码
        try {
            if(captchaCheck){
                captchaService.check(dto.getUuid(), dto.getCode());
        if(type!= Constants.TWO){
            try {
                if(captchaCheck){
                    captchaService.check(dto.getUuid(), dto.getCode());
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage());
                loginLog.setSuccess(Boolean.FALSE);
                systemLoginLogService.create(loginLog);
                throw e;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage());
            loginLog.setSuccess(Boolean.FALSE);
            systemLoginLogService.create(loginLog);
            throw e;
        }
        // 校验用户名和密码
        Subject subject = SecurityUtils.getSubject();
@@ -74,7 +78,7 @@
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage());
            loginLog.setSuccess(Boolean.FALSE);
            systemLoginLogService.create(loginLog);
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(), Objects.isNull(e.getCause())?ResponseStatus.ACCOUNT_INCORRECT.getMessage():e.getCause().getMessage());
        }
    }
}