This commit is contained in:
Dftre 2024-07-21 16:05:52 +08:00
parent 39b8586bfd
commit 5e972f21c5
3 changed files with 14 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.auth.common.domain.OauthUser;
import com.ruoyi.auth.common.service.IOauthUserService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
@ -15,8 +17,6 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpClientUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
import com.ruoyi.auth.common.domain.OauthUser;
import com.ruoyi.auth.common.service.IOauthUserService;
import com.ruoyi.oauth.wx.constant.WxMiniAppConstant;
import com.ruoyi.oauth.wx.constant.WxPubConstant;
import com.ruoyi.oauth.wx.service.WxLoginService;
@ -29,12 +29,16 @@ public class WxLoginServiceImpl implements WxLoginService {
@Autowired
private WxPubConstant wxH5Constant;
@Autowired
private TokenService tokenService;
@Autowired
private UserDetailsServiceImpl userDetailsServiceImpl;
@Autowired
private ISysUserService userService;
@Autowired
private IOauthUserService oauthUserService;

View File

@ -33,6 +33,7 @@ public class MailServiceImpl implements IMailService {
private TokenService tokenService;
@Autowired
private UserDetailsServiceImpl userDetailsServiceImpl;
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
@Override
@ -78,6 +79,7 @@ public class MailServiceImpl implements IMailService {
sysUser.setUserName(loginBody.getEmail());
sysUser.setPassword(SecurityUtils.encryptPassword(RandomCodeUtil.code(16)));
sysUser.setEmail(loginBody.getEmail());
userService.registerUser(sysUser);
} else {
throw new ServiceException("该邮箱未绑定用户");
}
@ -104,6 +106,7 @@ public class MailServiceImpl implements IMailService {
sysUser.setUserName(registerBody.getEmail());
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
sysUser.setEmail(registerBody.getEmail());
userService.registerUser(sysUser);
} else {
throw new ServiceException("验证码错误");
}

View File

@ -43,7 +43,6 @@ public class DySmsServiceImpl implements DySmsService {
private TokenService tokenService;
private static final Logger log = LoggerFactory.getLogger(DySmsServiceImpl.class);
@Override
public boolean sendCode(String phone, String code, OauthVerificationUse use) {
if (CacheUtils.hasKey(CacheConstants.PHONE_CODES, use.getValue() + phone)) {
@ -89,6 +88,7 @@ public class DySmsServiceImpl implements DySmsService {
sysUser.setUserName(loginBody.getPhonenumber());
sysUser.setPassword(SecurityUtils.encryptPassword(RandomCodeUtil.code(16)));
sysUser.setPhonenumber(loginBody.getPhonenumber());
userService.registerUser(sysUser);
} else {
throw new ServiceException("该手机号未绑定用户");
}
@ -109,12 +109,13 @@ public class DySmsServiceImpl implements DySmsService {
}
}
public void doRegisterVerify(RegisterBody registerBody) {
public boolean doRegisterVerify(RegisterBody registerBody) {
if (checkCode(registerBody.getPhonenumber(), registerBody.getCode(), OauthVerificationUse.REGISTER)) {
SysUser sysUser = new SysUser();
sysUser.setUserName(registerBody.getPhonenumber());
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
sysUser.setPhonenumber(registerBody.getPhonenumber());
return userService.registerUser(sysUser);
} else {
throw new ServiceException("验证码错误");
}
@ -151,14 +152,14 @@ public class DySmsServiceImpl implements DySmsService {
sendCode(loginBody.getPhonenumber(), RandomCodeUtil.numberCode(6), OauthVerificationUse.BIND);
}
public void doBindVerify(LoginBody loginBody) {
public int doBindVerify(LoginBody loginBody) {
if (checkCode(loginBody.getPhonenumber(), loginBody.getCode(), OauthVerificationUse.BIND)) {
SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
if (!SecurityUtils.matchesPassword(loginBody.getPassword(), sysUser.getPassword())) {
throw new ServiceException("密码错误");
}
sysUser.setPhonenumber(loginBody.getPhonenumber());
userService.updateUser(sysUser);
return userService.updateUser(sysUser);
} else {
throw new ServiceException("验证码错误");
}