mitao
2024-05-17 15d3e08bb9f96d498798738d902008518ee3585c
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
@@ -1,7 +1,5 @@
package com.ruoyi.auth.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.SecurityConstants;
@@ -17,6 +15,8 @@
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 登录校验方法
@@ -140,4 +140,25 @@
        }
        recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
    }
    public void changePassword(String username, String password, String verificationCode) {
        String verificationCodeCache = Convert.toStr(
                redisService.getCacheObject(
                        CacheConstants.CHANGE_PASSWORD_CAPTCHA_CODE_KEY + username));
        if (StringUtils.isEmpty(verificationCodeCache)) {
            throw new ServiceException("验证码已过期,请重新获取!");
        }
        if (!verificationCodeCache.equals(verificationCode)) {
            throw new ServiceException("验证码错误,请重新输入!");
        }
        R<LoginUser> userInfo = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
        if (R.FAIL == userInfo.getCode()) {
            throw new ServiceException(userInfo.getMsg());
        }
        if (!passwordService.matches(userInfo.getData().getSysUser(), password)) {
            throw new ServiceException("旧密码错误,请重新输入!");
        }
        remoteUserService.changePassword(username, SecurityUtils.encryptPassword(password),
                SecurityConstants.INNER);
    }
}