用户注册基本完成
This commit is contained in:
parent
3e5e6765ec
commit
6e6423f583
@ -83,6 +83,20 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--用于加密-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -113,4 +113,21 @@ public class CommonUtil {
|
|||||||
public static long getCurrentTimestamp(){
|
public static long getCurrentTimestamp(){
|
||||||
return System.currentTimeMillis();
|
return System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 生成指定长度随机串
|
||||||
|
*
|
||||||
|
* @param length
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static final String ALL_CHAR_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
public static String getStringNumRandom(int length) {
|
||||||
|
//生成随机数字和字母,
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder saltString = new StringBuilder(length);
|
||||||
|
for (int i = 1; i <= length; ++i) {
|
||||||
|
saltString.append(ALL_CHAR_NUM.charAt(random.nextInt(ALL_CHAR_NUM.length())));
|
||||||
|
}
|
||||||
|
return saltString.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class NotifyServiceImpl implements NotifyService {
|
|||||||
* 验证码格式
|
* 验证码格式
|
||||||
* todo 对60s的思考
|
* todo 对60s的思考
|
||||||
*/
|
*/
|
||||||
private static final String CONTENT = "您的验证码是%s,有效时间为60秒";
|
private static final String CONTENT = "您的验证码是%s,有效时间为10分钟";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 十分钟有效
|
* 十分钟有效
|
||||||
|
@ -9,7 +9,9 @@ import net.jieyuu.request.UserRegisterRequest;
|
|||||||
import net.jieyuu.service.NotifyService;
|
import net.jieyuu.service.NotifyService;
|
||||||
import net.jieyuu.service.UserService;
|
import net.jieyuu.service.UserService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import net.jieyuu.utils.CommonUtil;
|
||||||
import net.jieyuu.utils.JsonData;
|
import net.jieyuu.utils.JsonData;
|
||||||
|
import org.apache.commons.codec.digest.Md5Crypt;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -43,15 +45,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
* 插入数据库
|
* 插入数据库
|
||||||
* 新注册用户福利发放 TODO
|
* 新注册用户福利发放 TODO
|
||||||
*
|
*
|
||||||
* @param userRegisterRequest
|
* @param registerRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JsonData register(UserRegisterRequest userRegisterRequest) {
|
public JsonData register(UserRegisterRequest registerRequest) {
|
||||||
boolean checkCode = false;
|
boolean checkCode = false;
|
||||||
//校验验证码
|
//校验验证码
|
||||||
if (StringUtils.isNotBlank(userRegisterRequest.getMail())) {
|
if (StringUtils.isNotBlank(registerRequest.getMail())) {
|
||||||
checkCode = notifyService.checkCode(SendCodeEnum.USER_REGISTER, userRegisterRequest.getMail(), userRegisterRequest.getCode());
|
checkCode = notifyService.checkCode(SendCodeEnum.USER_REGISTER, registerRequest.getMail(), registerRequest.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkCode) {
|
if (!checkCode) {
|
||||||
@ -60,14 +62,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserDO userDO = new UserDO();
|
UserDO userDO = new UserDO();
|
||||||
BeanUtils.copyProperties(userRegisterRequest, userDO);
|
BeanUtils.copyProperties(registerRequest, userDO);
|
||||||
|
|
||||||
//设置创建时间
|
//设置创建时间
|
||||||
userDO.setCreateTime(new Date());
|
userDO.setCreateTime(new Date());
|
||||||
//todo 思考老师的设置是否有问题
|
|
||||||
// userDO.setSlogan("");
|
|
||||||
//todo 设置密码 加密
|
//todo 设置密码 加密
|
||||||
// userDO.setPwd(userRegisterRequest.getPwd());
|
// userDO.setPwd(userRegisterRequest.getPwd());
|
||||||
|
//生成密钥 盐
|
||||||
|
userDO.setSecret("$1$" + CommonUtil.getStringNumRandom(8));
|
||||||
|
|
||||||
|
//密码加盐处理
|
||||||
|
String cryptPwd = Md5Crypt.md5Crypt(userDO.getPwd().getBytes(), userDO.getSecret());
|
||||||
|
userDO.setPwd(cryptPwd);
|
||||||
|
|
||||||
//账号唯一性检查 todo
|
//账号唯一性检查 todo
|
||||||
if (checkUnique(userDO.getMail())) {
|
if (checkUnique(userDO.getMail())) {
|
||||||
@ -87,16 +94,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验用户账号唯一
|
* 校验用户账号唯一
|
||||||
|
*
|
||||||
* @param mail
|
* @param mail
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean checkUnique(String mail) {
|
private boolean checkUnique(String mail) {
|
||||||
return false;
|
//todo : 实现
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户注册,初始化福利信息 todo
|
* 用户注册,初始化福利信息 todo
|
||||||
|
*
|
||||||
* @param userDO
|
* @param userDO
|
||||||
*/
|
*/
|
||||||
private void userRegisterInitTask(UserDO userDO) {
|
private void userRegisterInitTask(UserDO userDO) {
|
||||||
|
Loading…
Reference in New Issue
Block a user