com.ruoyi.framework.manager.AsyncManager Java Examples

The following examples show how to use com.ruoyi.framework.manager.AsyncManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogoutSuccessHandlerImpl.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 退出处理
 * 
 * @return
 */
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException
{
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser))
    {
        String userName = loginUser.getUsername();
        // 删除用户缓存记录
        tokenService.delLoginUser(loginUser.getToken());
        // 记录用户退出日志
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功"));
    }
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "退出成功")));
}
 
Example #2
Source File: LogoutFilter.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response){
    try {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        SysUser user = ShiroUtils.getSysUser();
        if (ObjectUtil.isNotNull(user)) {
            String loginName = user.getLoginName();
            // 记录用户退出日志
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
            // 清理缓存
            cache.remove(loginName);
        }
        // 退出登录
        subject.logout();
        issueRedirect(request, response, redirectUrl);
    } catch (Exception e) {
        log.error("Encountered session exception during logout.  This can generally safely be ignored." , e);
    }
    return false;
}
 
Example #3
Source File: LogoutFilter.java    From supplierShop with MIT License 5 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception
{
    try
    {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        try
        {
            SysUser user = ShiroUtils.getSysUser();
            if (StringUtils.isNotNull(user))
            {
                String loginName = user.getLoginName();
                // 记录用户退出日志
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
                // 清理缓存
                cache.remove(loginName);
            }
            // 退出登录
            subject.logout();
        }
        catch (SessionException ise)
        {
            log.error("logout fail.", ise);
        }
        issueRedirect(request, response, redirectUrl);
    }
    catch (Exception e)
    {
        log.error("Encountered session exception during logout.  This can generally safely be ignored.", e);
    }
    return false;
}
 
Example #4
Source File: OnlineSessionDAO.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 更新会话;如更新会话最后访问时间/停止会话/设置超时时间/设置移除属性等会调用
 */
public void syncToDb(OnlineSession onlineSession)
{
    Date lastSyncTimestamp = (Date) onlineSession.getAttribute(LAST_SYNC_DB_TIMESTAMP);
    if (lastSyncTimestamp != null)
    {
        boolean needSync = true;
        long deltaTime = onlineSession.getLastAccessTime().getTime() - lastSyncTimestamp.getTime();
        if (deltaTime < dbSyncPeriod * 60 * 1000)
        {
            // 时间差不足 无需同步
            needSync = false;
        }
        // isGuest = true 访客
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;

        // session 数据变更了 同步
        if (isGuest == false && onlineSession.isAttributeChanged())
        {
            needSync = true;
        }

        if (needSync == false)
        {
            return;
        }
    }
    // 更新上次同步数据库时间
    onlineSession.setAttribute(LAST_SYNC_DB_TIMESTAMP, onlineSession.getLastAccessTime());
    // 更新完后 重置标识
    if (onlineSession.isAttributeChanged())
    {
        onlineSession.resetAttributeChanged();
    }
    AsyncManager.me().execute(AsyncFactory.syncSessionToDb(onlineSession));
}
 
Example #5
Source File: LogoutFilter.java    From ruoyiplus with MIT License 5 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception
{
    try
    {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        try
        {
            SysUser user = ShiroUtils.getSysUser();
            if (StringUtils.isNotNull(user))
            {
                String loginName = user.getLoginName();
                // 记录用户退出日志
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
            }
            // 退出登录
            subject.logout();
        }
        catch (SessionException ise)
        {
            log.error("logout fail.", ise);
        }
        issueRedirect(request, response, redirectUrl);
    }
    catch (Exception e)
    {
        log.error("Encountered session exception during logout.  This can generally safely be ignored.", e);
    }
    return false;
}
 
Example #6
Source File: OnlineSessionDAO.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 更新会话;如更新会话最后访问时间/停止会话/设置超时时间/设置移除属性等会调用
 */
public void syncToDb(OnlineSession onlineSession)
{
    Date lastSyncTimestamp = (Date) onlineSession.getAttribute(LAST_SYNC_DB_TIMESTAMP);
    if (lastSyncTimestamp != null)
    {
        boolean needSync = true;
        long deltaTime = onlineSession.getLastAccessTime().getTime() - lastSyncTimestamp.getTime();
        if (deltaTime < dbSyncPeriod * 60 * 1000)
        {
            // 时间差不足 无需同步
            needSync = false;
        }
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;

        // session 数据变更了 同步
        if (isGuest == false && onlineSession.isAttributeChanged())
        {
            needSync = true;
        }

        if (needSync == false)
        {
            return;
        }
    }
    onlineSession.setAttribute(LAST_SYNC_DB_TIMESTAMP, onlineSession.getLastAccessTime());
    // 更新完后 重置标识
    if (onlineSession.isAttributeChanged())
    {
        onlineSession.resetAttributeChanged();
    }
    AsyncManager.me().execute(AsyncFactory.syncSessionToDb(onlineSession));
}
 
Example #7
Source File: OnlineSessionDAO.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 更新会话;如更新会话最后访问时间/停止会话/设置超时时间/设置移除属性等会调用
 */
public void syncToDb(OnlineSession onlineSession) {
    Date lastSyncTimestamp = (Date) onlineSession.getAttribute(LAST_SYNC_DB_TIMESTAMP);
    if (lastSyncTimestamp != null) {
        boolean needSync = true;
        long deltaTime = onlineSession.getLastAccessTime().getTime() - lastSyncTimestamp.getTime();
        if (deltaTime < dbSyncPeriod * 60 * 1000) {
            // 时间差不足 无需同步
            needSync = false;
        }
        boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;

        // session 数据变更了 同步
        if (!isGuest && onlineSession.isAttributeChanged()) {
            needSync = true;
        }

        if (!needSync) {
            return;
        }
    }
    onlineSession.setAttribute(LAST_SYNC_DB_TIMESTAMP, onlineSession.getLastAccessTime());
    // 更新完后 重置标识
    if (onlineSession.isAttributeChanged()) {
        onlineSession.resetAttributeChanged();
    }
    AsyncManager.me().execute(AsyncFactory.syncSessionToDb(onlineSession));
}
 
Example #8
Source File: LogAspect.java    From supplierShop with MIT License 4 votes vote down vote up
protected void handleLog(final JoinPoint joinPoint, final Exception e)
{
    try
    {
        // 获得注解
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null)
        {
            return;
        }

        // 获取当前的用户
        SysUser currentUser = ShiroUtils.getSysUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = ShiroUtils.getIp();
        operLog.setOperIp(ip);

        operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
        if (currentUser != null)
        {
            operLog.setOperName(currentUser.getLoginName());
            if (StringUtils.isNotNull(currentUser.getDept())
                    && StringUtils.isNotEmpty(currentUser.getDept().getDeptName()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }

        if (e != null)
        {
            operLog.setStatus(BusinessStatus.FAIL.ordinal());
            operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        }
        // 设置方法名称
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        operLog.setMethod(className + "." + methodName + "()");
        // 处理设置注解上的参数
        getControllerMethodDescription(controllerLog, operLog);
        // 保存数据库
        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
    }
    catch (Exception exp)
    {
        // 记录本地异常日志
        log.error("==前置通知异常==");
        log.error("异常信息:{}", exp.getMessage());
        exp.printStackTrace();
    }
}
 
Example #9
Source File: SysLoginService.java    From supplierShop with MIT License 4 votes vote down vote up
/**
     * 登录
     */
    public SysUser login(String username, String password)
    {
        // 验证码校验
//        if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
//        {
//            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
//            throw new CaptchaException();
//        }
        // 用户名或密码为空 错误
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
            throw new UserNotExistsException();
        }
        // 密码如果不在指定范围内 错误
        if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
                || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        }

        // 用户名不在指定范围内 错误
        if (username.length() < UserConstants.USERNAME_MIN_LENGTH
                || username.length() > UserConstants.USERNAME_MAX_LENGTH)
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        }

        // 查询用户信息
        SysUser user = userService.selectUserByLoginName(username);

        if (user == null && maybeMobilePhoneNumber(username))
        {
            user = userService.selectUserByPhoneNumber(username);
        }

        if (user == null && maybeEmail(username))
        {
            user = userService.selectUserByEmail(username);
        }

        if (user == null)
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
            throw new UserNotExistsException();
        }
        
        if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
            throw new UserDeleteException();
        }
        
        if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark())));
            throw new UserBlockedException();
        }

        passwordService.validate(user, password);

        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
        recordLoginInfo(user);
        return user;
    }
 
Example #10
Source File: LogAspect.java    From RuoYi-Vue with MIT License 4 votes vote down vote up
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult)
{
    try
    {
        // 获得注解
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null)
        {
            return;
        }

        // 获取当前的用户
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
        operLog.setOperIp(ip);
        // 返回参数
        operLog.setJsonResult(JSON.toJSONString(jsonResult));

        operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
        if (loginUser != null)
        {
            operLog.setOperName(loginUser.getUsername());
        }

        if (e != null)
        {
            operLog.setStatus(BusinessStatus.FAIL.ordinal());
            operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        }
        // 设置方法名称
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        operLog.setMethod(className + "." + methodName + "()");
        // 设置请求方式
        operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
        // 处理设置注解上的参数
        getControllerMethodDescription(joinPoint, controllerLog, operLog);
        // 保存数据库
        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
    }
    catch (Exception exp)
    {
        // 记录本地异常日志
        log.error("==前置通知异常==");
        log.error("异常信息:{}", exp.getMessage());
        exp.printStackTrace();
    }
}
 
Example #11
Source File: SysLoginService.java    From RuoYi-Vue with MIT License 4 votes vote down vote up
/**
 * 登录验证
 * 
 * @param username 用户名
 * @param password 密码
 * @param captcha 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid)
{
    String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
    String captcha = redisCache.getCacheObject(verifyKey);
    redisCache.deleteObject(verifyKey);
    if (captcha == null)
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
        throw new CaptchaExpireException();
    }
    if (!code.equalsIgnoreCase(captcha))
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
        throw new CaptchaException();
    }
    // 用户验证
    Authentication authentication = null;
    try
    {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager
                .authenticate(new UsernamePasswordAuthenticationToken(username, password));
    }
    catch (Exception e)
    {
        if (e instanceof BadCredentialsException)
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        }
        else
        {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new CustomException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    // 生成token
    return tokenService.createToken(loginUser);
}
 
Example #12
Source File: LogAspect.java    From ruoyiplus with MIT License 4 votes vote down vote up
protected void handleLog(final JoinPoint joinPoint, final Exception e)
{
    try
    {
        // 获得注解
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null)
        {
            return;
        }

        // 获取当前的用户
        SysUser currentUser = ShiroUtils.getSysUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = ShiroUtils.getIp();
        operLog.setOperIp(ip);

        operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
        if (currentUser != null)
        {
            operLog.setOperName(currentUser.getLoginName());
            if (StringUtils.isNotNull(currentUser.getDept())
                    && StringUtils.isNotEmpty(currentUser.getDept().getDeptName()))
            {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }

        if (e != null)
        {
            operLog.setStatus(BusinessStatus.FAIL.ordinal());
            operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        }
        // 设置方法名称
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        operLog.setMethod(className + "." + methodName + "()");
        // 处理设置注解上的参数
        getControllerMethodDescription(controllerLog, operLog);
        // 保存数据库
        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
    }
    catch (Exception exp)
    {
        // 记录本地异常日志
        log.error("==前置通知异常==");
        log.error("异常信息:{}", exp.getMessage());
        exp.printStackTrace();
    }
}
 
Example #13
Source File: SysLoginService.java    From ruoyiplus with MIT License 4 votes vote down vote up
/**
 * 登录
 */
public SysUser login(String username, String password)
{
    // 验证码校验
    if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
        throw new CaptchaException();
    }
    // 用户名或密码为空 错误
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
        throw new UserNotExistsException();
    }
    // 密码如果不在指定范围内 错误
    if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
            || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 用户名不在指定范围内 错误
    if (username.length() < UserConstants.USERNAME_MIN_LENGTH
            || username.length() > UserConstants.USERNAME_MAX_LENGTH)
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 查询用户信息
    SysUser user = userService.selectUserByLoginName(username);

    if (user == null && maybeMobilePhoneNumber(username))
    {
        user = userService.selectUserByPhoneNumber(username);
    }

    if (user == null && maybeEmail(username))
    {
        user = userService.selectUserByEmail(username);
    }

    if (user == null)
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
        throw new UserNotExistsException();
    }
    
    if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
        throw new UserDeleteException();
    }
    
    if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
    {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark())));
        throw new UserBlockedException();
    }

    passwordService.validate(user, password);

    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    recordLoginInfo(user);
    return user;
}
 
Example #14
Source File: LogAspect.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
private void handleLog(final JoinPoint joinPoint, final Exception e) {
    try {
        // 获得注解
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null) {
            return;
        }

        // 获取当前的用户
        SysUser currentUser = ShiroUtils.getSysUser();

        // *========数据库日志=========*//
        SysOperLog operLog = new SysOperLog();
        operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
        // 请求的地址
        String ip = ShiroUtils.getIp();
        operLog.setOperIp(ip);

        operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
        if (ObjectUtil.isNotNull(currentUser)) {
            operLog.setOperName(currentUser.getLoginName());
            if (ObjectUtil.isNotNull(currentUser.getDept())
                    && StrUtil.isNotEmpty(currentUser.getDept().getDeptName())) {
                operLog.setDeptName(currentUser.getDept().getDeptName());
            }
        }

        if (e != null) {
            operLog.setStatus(BusinessStatus.FAIL.ordinal());
            operLog.setErrorMsg(StrUtil.sub(e.getMessage(), 0, 2000));
        }
        // 设置方法名称
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        operLog.setMethod(className + "." + methodName + "()");
        // 处理设置注解上的参数
        getControllerMethodDescription(controllerLog, operLog);
        // 保存数据库
        AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
    } catch (Exception exp) {
        // 记录本地异常日志
        log.error("==前置通知异常==",exp);
        log.error("异常信息:{}" , exp.getMessage());
    }
}
 
Example #15
Source File: SysLoginService.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
/**
 * 登录
 */
public SysUser login(String username, String password) {
    // 验证码校验
    if (ObjectUtil.isNotEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA))) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
        throw new CaptchaException();
    }
    // 用户名或密码为空 错误
    if (StrUtil.isEmpty(username) || StrUtil.isEmpty(password)) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
        throw new UserNotExistsException();
    }
    // 密码如果不在指定范围内 错误
    if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
            || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 用户名不在指定范围内 错误
    if (username.length() < UserConstants.USERNAME_MIN_LENGTH
            || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 查询用户信息
    SysUser user = userService.selectUserByLoginName(username);

    if (user == null && maybeMobilePhoneNumber(username)) {
        user = userService.selectUserByPhoneNumber(username);
    }

    if (user == null && maybeEmail(username)) {
        user = userService.selectUserByEmail(username);
    }

    if (user == null) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
        throw new UserNotExistsException();
    }

    if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
        throw new UserDeleteException();
    }

    if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked" , user.getRemark())));
        throw new UserBlockedException();
    }

    passwordService.validate(user, password);

    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    recordLoginInfo(user);
    return user;
}