1
luodangjia
2025-01-21 959aae945779b5e46d5d362e371a0c3b746e2b9f
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
@@ -19,6 +19,7 @@
import com.ruoyi.company.api.RemoteCompanyUserService;
import com.ruoyi.company.api.domain.Company;
import com.ruoyi.company.api.domain.User;
import com.ruoyi.company.api.domain.dto.MgtCompanyDTO;
import com.ruoyi.company.api.model.RegisterUser;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
@@ -148,7 +149,7 @@
        recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
    }
    public void companyRegister(RegisterUser registerUser) {
    public void companyRegister(MgtCompanyDTO registerUser) {
        String accountName = registerUser.getAccountName();
        String password = registerUser.getPassword();
        // 用户名或密码为空 错误
@@ -204,10 +205,21 @@
    public void resetPwd(RegisterUser registerUser) {
        R<User> userR = resetPwdCheck(registerUser);
        User user = userR.getData();
        String password = SecurityUtils.encryptPassword(registerUser.getPassword());
        user.setPassword(password);
        R<Void> r = remoteCompanyUserService.updateUser(user);
        if (R.isError(r)) {
            throw new ServiceException(userR.getMsg());
        }
    }
    public R<User> resetPwdCheck(RegisterUser registerUser) {
        String accountName = registerUser.getAccountName();
        R<User> userByPhoneR = remoteCompanyUserService.getUserByPhone(accountName, SecurityConstants.INNER);
        if (R.isError(userByPhoneR)) {
            throw new ServiceException(userByPhoneR.getMsg());
            throw new RuntimeException(userByPhoneR.getMsg());
        }
        boolean check = false;
        R<User> userR = new R<>();
@@ -217,24 +229,17 @@
        if (!check){
            userR = remoteCompanyUserService.getUserByAccountName(accountName, SecurityConstants.INNER);
            if (R.isError(userR)) {
                throw new ServiceException(userR.getMsg());
                throw new RuntimeException(userR.getMsg());
            }
            if (userR.getData() == null) {
                throw new ServiceException("账号不存在");
                throw new RuntimeException("账号不存在");
            }
            check = check(userR.getData(), registerUser.getCompanyName(), registerUser.getIdCardNumber());
        }
        if (!check) {
            throw new ServiceException("账号不存在");
            throw new RuntimeException("账号不存在");
        }
        String password = SecurityUtils.encryptPassword(registerUser.getPassword());
        User user = userR.getData();
        user.setPassword(password);
        R<Void> r = remoteCompanyUserService.updateUser(user);
        if (R.isError(r)) {
            throw new ServiceException(userR.getMsg());
        }
        return userR;
    }
    public boolean check(User user, String companyName, String idCardNumber) {
@@ -264,7 +269,7 @@
        if (Objects.isNull(sysUser)){
            throw new ServiceException("用户不存在");
        }
        if (!SecurityUtils.matchesPassword(SecurityUtils.encryptPassword(dto.getOldPassword()), sysUser.getPassword())){
        if (!SecurityUtils.matchesPassword(dto.getOldPassword(), sysUser.getPassword())){
            throw new ServiceException("原密码错误");
        }
        sysUser.setPassword(SecurityUtils.encryptPassword(dto.getNewPassword()));