1.用户邮箱登录注册接口实现
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package vvpkassistant.User.service;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.temp.SaTempUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -15,7 +16,7 @@ import vvpkassistant.User.model.UserModel;
|
||||
import vvpkassistant.User.model.UserModelVO;
|
||||
import vvpkassistant.common.ErrorCode;
|
||||
import vvpkassistant.exception.BusinessException;
|
||||
import vvpkassistant.mail.model.MailModel;
|
||||
import vvpkassistant.mail.service.MailService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -31,6 +32,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
|
||||
|
||||
@Resource
|
||||
private WxChatParam wxChatParam;
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@Override
|
||||
public UserModelVO loginWithMail(UserModelDTO model) {
|
||||
@@ -96,33 +99,52 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserModelVO addUserWithMail(UserModelDTO model) {
|
||||
public UserModelVO addUserWithMail(UserModelDTO userModelDTO) {
|
||||
|
||||
LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserModel::getEmail,model.getEmail());
|
||||
lambdaQueryWrapper.eq(UserModel::getEmail,userModelDTO.getEmail());
|
||||
UserModel userModel = userDao.selectOne(lambdaQueryWrapper);
|
||||
if (userModel != null) {
|
||||
throw new BusinessException(ErrorCode.MAIL_ALREADY_EXIST);
|
||||
}
|
||||
if (model.getPassword().length() < 6 ){
|
||||
if (userModelDTO.getPassword().length() < 6 ){
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR,"密码长度不能小于 6 位");
|
||||
}
|
||||
model.setPassword(BcryptUtils.encryptPassword(model.getPassword()));
|
||||
model.setCreateTime(VVTools.currentTimeStamp());
|
||||
//设置状态为正常
|
||||
model.setStatus(2);
|
||||
userModelDTO.setPassword(BcryptUtils.encryptPassword(userModelDTO.getPassword()));
|
||||
userModelDTO.setCreateTime(VVTools.currentTimeStamp());
|
||||
//设置状态为待验证
|
||||
userModelDTO.setStatus(2);
|
||||
//设置积分为0
|
||||
model.setPoints(0);
|
||||
userDao.insert(BeanUtil.copyProperties(model, UserModel.class));
|
||||
userModelDTO.setPoints(0);
|
||||
UserModel userModelEntity = BeanUtil.copyProperties(userModelDTO, UserModel.class);
|
||||
if ( userDao.insert(userModelEntity) != 1){
|
||||
throw new BusinessException(ErrorCode.ADD_FAILED,"用户注册失败");
|
||||
}
|
||||
mailService.sendMail(userModelDTO.getEmail(),userModelEntity.getId());
|
||||
// 判断用户是否为邀请用户
|
||||
if (model.getInviterId() != null) {
|
||||
UserModel oldUser = userDao.selectById(model.getInviterId());
|
||||
if (userModelDTO.getInviterId() != null) {
|
||||
UserModel oldUser = userDao.selectById(userModelDTO.getInviterId());
|
||||
oldUser.setPoints(oldUser.getPoints() + 10);
|
||||
userDao.updateById(oldUser);
|
||||
}
|
||||
UserModelVO userModelVO = BeanUtil.copyProperties(model, UserModelVO.class);
|
||||
UserModelVO userModelVO = BeanUtil.copyProperties(userModelEntity, UserModelVO.class);
|
||||
userModelVO.setNewAccount(true);
|
||||
userModelVO.setChatInfo(wxChatParam);
|
||||
return userModelVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean activateAccount(String token) {
|
||||
Integer userId = SaTempUtil.parseToken(token, Integer.class);
|
||||
UserModel userModel = userDao.selectById(userId);
|
||||
if (userModel == null) {
|
||||
throw new BusinessException(ErrorCode.USER_DOES_NOT_EXIST);
|
||||
}
|
||||
userModel.setStatus(0);
|
||||
if (userDao.updateById(userModel) == 1){
|
||||
return true;
|
||||
}else {
|
||||
throw new BusinessException(ErrorCode.UPDATE_FAILED,"激活失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user