新增注册功能 通过手机号注册账号90%
This commit is contained in:
@ -6,9 +6,10 @@ import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.PhoneCode;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bookmarkhtml.Const;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -26,7 +27,8 @@ public class RegisterPhoneController extends BaseController
|
||||
@Autowired
|
||||
private ISqMenuService iSqMenuService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
/**
|
||||
* 发送注册验证码
|
||||
*/
|
||||
@ -35,11 +37,23 @@ public class RegisterPhoneController extends BaseController
|
||||
{
|
||||
AjaxResult ajaxResult = new AjaxResult();
|
||||
ajaxResult.put("code", HttpStatus.SUCCESS);
|
||||
|
||||
if (StringUtils.isEmpty(phone)){
|
||||
ajaxResult.put("msg", "非法手机号,请重新输入!");
|
||||
return ajaxResult;
|
||||
}
|
||||
int phoneCount = userService.countUserByPhone(phone);
|
||||
if (phoneCount != 0) {
|
||||
ajaxResult.put("msg", "此手机账号已经被使用,请前往登陆!");
|
||||
return ajaxResult;
|
||||
}
|
||||
|
||||
Long time = 3600L;//限制规定时间内 访问次数
|
||||
//防止重复点击
|
||||
boolean phoneCodelFlag = iSqMenuService.countRepetition(Const.PHONE_REGISTER,getAuthUser().getUserId(),3600L,10); //3600秒 最多请求10次验证码
|
||||
boolean phoneCodelFlag = iSqMenuService.countRepetition(Const.PHONE_REGISTER,Long.valueOf(phone),time,10); //3600秒 最多请求10次验证码
|
||||
|
||||
if(!phoneCodelFlag){
|
||||
ajaxResult.put("msg","短时间内发送频繁,请稍后再操作!");
|
||||
ajaxResult.put("msg","短时间内发送频繁,请过几个小时就再操作!");
|
||||
return ajaxResult;
|
||||
}
|
||||
|
||||
@ -50,7 +64,8 @@ public class RegisterPhoneController extends BaseController
|
||||
ajaxResult.put("msg","短信发送成功,请在"+Constants.CAPTCHA_PHONE_EXPIRATION+"分钟内验证。");
|
||||
return ajaxResult;
|
||||
}else {
|
||||
ajaxResult.put("msg","短信发送失败");
|
||||
ajaxResult.put("code", HttpStatus.ERROR);
|
||||
ajaxResult.put("msg","系统错误,短信发送失败,请稍后再试!");
|
||||
return ajaxResult;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,11 @@ package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.model.RegisterBody;
|
||||
import com.ruoyi.common.core.redis.RedisKey;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -39,21 +44,32 @@ public class SysLoginController
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
/**
|
||||
* 注册方法
|
||||
*
|
||||
* @param loginBody 注册信息
|
||||
* @param registerBody 注册信息
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/registerUser")
|
||||
public AjaxResult registerUser(@RequestBody LoginBody loginBody)
|
||||
{
|
||||
public AjaxResult registerUser(@RequestBody RegisterBody registerBody) {
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.registerUser(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
||||
loginBody.getUuid(),loginBody.getEmail(),loginBody.getPhone());
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
|
||||
String msg = loginService.registerUser(registerBody.getUsername(), registerBody.getPassword(), registerBody.getPhoneCode(),
|
||||
registerBody.getUuid(), registerBody.getEmail(), registerBody.getPhone());
|
||||
|
||||
if (Constants.LOGIN_SUCCESS.equals(msg)) {
|
||||
ajax.put("msg", "注册成功,请前往登陆!");
|
||||
} else if (Constants.LOGIN_FAIL.equals(msg)) {
|
||||
ajax.put("code", HttpStatus.ERROR);
|
||||
ajax.put("msg", "注册失败,系统错误,请稍后再尝试!");
|
||||
} else {
|
||||
ajax.put("code", HttpStatus.ERROR);
|
||||
ajax.put("msg", msg);
|
||||
}
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.github.wujun234.uid.UidGenerator;
|
||||
import com.ruoyi.bookmark.service.ISqMenuService;
|
||||
import com.ruoyi.common.core.redis.RedisUtil;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.bookmarkhtml.Const;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -25,12 +26,9 @@ public class UIDTest extends BaseSpringBootTest{
|
||||
private UidGenerator cachedUidGenerator;
|
||||
@Autowired
|
||||
private ISqMenuService iSqMenuService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Test
|
||||
public void testSerialGenerate() {
|
||||
// Generate UID
|
||||
long cachedUidGeneratoruid = cachedUidGenerator.getUID();
|
||||
long defaultUidGeneratoruid = defaultUidGenerator.getUID(); //用这个
|
||||
|
||||
@ -38,11 +36,6 @@ public class UIDTest extends BaseSpringBootTest{
|
||||
System.out.println("cachedUidGeneratoruid解密:"+cachedUidGenerator.parseUID(cachedUidGeneratoruid));
|
||||
System.out.println("defaultUidGeneratoruid:"+defaultUidGeneratoruid);
|
||||
System.out.println("defaultUidGeneratoruid解密:"+cachedUidGenerator.parseUID(defaultUidGeneratoruid));
|
||||
|
||||
// Parse UID into [Timestamp, WorkerId, Sequence]
|
||||
// {"UID":"450795408770","timestamp":"2019-02-20 14:55:39","workerId":"27","sequence":"2"}
|
||||
// System.out.println(cachedUidGenerator.parseUID(uid));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void dateTest(){
|
||||
@ -64,5 +57,27 @@ public class UIDTest extends BaseSpringBootTest{
|
||||
}
|
||||
|
||||
|
||||
//密码加密
|
||||
@Test
|
||||
public void rest3(){
|
||||
String newPassword = "admin123";
|
||||
String password =SecurityUtils.encryptPassword(newPassword);
|
||||
System.out.println(password);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//密码加密对比
|
||||
@Test
|
||||
public void rest4(){
|
||||
String newPassword = "2654430977wh";
|
||||
if( SecurityUtils.matchesPassword(newPassword, "$2a$10$zAx2lmzBNwmL.nFqfLmps.CsrSblAPtMvy29Ns9fwzeq8hIoKLT72")){ //newPassword 密码 password加密的后密码
|
||||
System.out.println("密码相同!");
|
||||
}else{
|
||||
System.out.println("密码不相同!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user