|
@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.index;
|
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
@@ -11,6 +12,7 @@ import com.ruoyi.common.enums.BusinessType;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.framework.web.service.SysLoginService;
|
|
|
import com.ruoyi.system.domain.KaoqinConfig;
|
|
|
import com.ruoyi.system.domain.KaoqinRecord;
|
|
|
import com.ruoyi.system.service.IKaoqinRecordService;
|
|
@@ -49,13 +51,13 @@ public class IndexController extends BaseController {
|
|
|
@Autowired
|
|
|
private IKaoqinRecordService kaoqinRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysLoginService loginService;
|
|
|
/**
|
|
|
* app新增用户
|
|
|
*/
|
|
|
@PostMapping
|
|
|
public AjaxResult add(@Validated @RequestBody SysUser user) {
|
|
|
- String phonenumber = user.getPhonenumber();
|
|
|
- user.setUserName(phonenumber);
|
|
|
if (!user.getCode().equals(redisCache.getCacheObject(CacheConstants.SMS_CODE_KEY+user.getPhonenumber()))) {
|
|
|
return error("新增用户'" + user.getUserName() + "'失败,短信验证码错误");
|
|
|
}
|
|
@@ -64,12 +66,24 @@ public class IndexController extends BaseController {
|
|
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
- } else if ("1".equals(checkStrongPwd(user.getPassword()))) {
|
|
|
+ }/* else if ("1".equals(checkStrongPwd(user.getPassword()))) {
|
|
|
return AjaxResult.error("密码必须包含数字、大小写字母、特殊符号且大于8位");
|
|
|
- }
|
|
|
+ }*/
|
|
|
user.setCreateBy("APP");
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ // 生成令牌
|
|
|
+ user.setCreateBy(getUsername());
|
|
|
+ //生成一个密码
|
|
|
+ //String password = randomPassword();
|
|
|
+ String password = user.getUserName()+"Abc#";
|
|
|
+ //todo 密码 要发送短信给用户
|
|
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
|
- return toAjax(userService.insertUserApp(user));
|
|
|
+ if (userService.insertUser(user) > 0){
|
|
|
+ String token = loginService.loginZhuCe(user.getUserName(), password);
|
|
|
+ ajax.put(Constants.TOKEN, token);
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+ return AjaxResult.error();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -184,4 +198,31 @@ public class IndexController extends BaseController {
|
|
|
map.put("y", yMpa);
|
|
|
return AjaxResult.success(map);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /** 随机出用户输入的密码位数的密码,从大小写字母,数字中取值 */
|
|
|
+ public static String randomPassword(){
|
|
|
+ char[] password = new char[8];//创建char数组接收每一位随机出来的密码
|
|
|
+ Random rand = new Random();
|
|
|
+ //在ASCII码表中,48-57 数字,65-90 大写字母,97-122 小写字母
|
|
|
+ for (int i = 0; i <password.length ; i++) {
|
|
|
+ int choice = rand.nextInt(4);
|
|
|
+ int lowercase = rand.nextInt(26)+65;//小写字母ASCII码表范围
|
|
|
+ int uppercase = rand.nextInt(26)+97;//大写字母ASCII码表范围
|
|
|
+ int figure = rand.nextInt(10)+48;//数字ASCII码表范围
|
|
|
+ int special = rand.nextInt(15) + 33;
|
|
|
+ //将 " 和 ' 替换成#
|
|
|
+ if (special == 34 || special == 39) {
|
|
|
+ special = 35;
|
|
|
+ }
|
|
|
+ switch (choice){//从大写字母.小写字母.数字中随机取值
|
|
|
+ case 0:password[i]=(char)lowercase;break;
|
|
|
+ case 1:password[i]=(char)uppercase;break;
|
|
|
+ case 2:password[i]=(char)figure;break;
|
|
|
+ case 3:password[i] = (char) special;break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new String(password);
|
|
|
+ }
|
|
|
}
|