Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roncoo
roncoo-education
提交
6c8da748
R
roncoo-education
项目概览
roncoo
/
roncoo-education
大约 1 年 前同步成功
通知
146
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roncoo-education
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6c8da748
编写于
7月 30, 2021
作者:
權赋
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
https://github.com/roncoo/roncoo-education
上级
29ca348a
28f68640
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
309 addition
and
286 deletion
+309
-286
pom.xml
pom.xml
+7
-0
roncoo-education-user/roncoo-education-user-service/src/main/java/com/roncoo/education/user/service/api/biz/ApiUserInfoBiz.java
...roncoo/education/user/service/api/biz/ApiUserInfoBiz.java
+296
-286
roncoo-education-util/pom.xml
roncoo-education-util/pom.xml
+6
-0
未找到文件。
pom.xml
浏览文件 @
6c8da748
...
...
@@ -215,6 +215,13 @@
<version>
2.16.2
</version>
</dependency>
<!-- hutool -->
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.3.8
</version>
</dependency>
<!-- jsoup -->
<dependency>
<groupId>
org.jsoup
</groupId>
...
...
roncoo-education-user/roncoo-education-user-service/src/main/java/com/roncoo/education/user/service/api/biz/ApiUserInfoBiz.java
浏览文件 @
6c8da748
package
com.roncoo.education.user.service.api.biz
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.RSA
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.roncoo.education.system.feign.interfaces.IFeignSys
;
import
com.roncoo.education.system.feign.vo.SysVO
;
...
...
@@ -19,7 +23,6 @@ import com.roncoo.education.util.base.Result;
import
com.roncoo.education.util.enums.*
;
import
com.roncoo.education.util.tools.*
;
import
com.xiaoleilu.hutool.crypto.DigestUtil
;
import
com.xiaoleilu.hutool.http.HttpUtil
;
import
com.xiaoleilu.hutool.util.ObjectUtil
;
import
com.xiaoleilu.hutool.util.RandomUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -39,49 +42,52 @@ import java.util.regex.Pattern;
@Component
public
class
ApiUserInfoBiz
extends
BaseBiz
{
@Autowired
private
IFeignSys
bossSys
;
@Autowired
private
PlatformDao
platformDao
;
@Autowired
private
UserDao
userDao
;
@Autowired
private
UserExtDao
userExtDao
;
@Autowired
private
SendSmsLogDao
sendSmsLogDao
;
@Autowired
private
UserLogLoginDao
userLogLoginDao
;
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
@Transactional
public
Result
<
UserLoginDTO
>
register
(
UserRegisterBO
userRegisterBO
)
{
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getPassword
()))
{
return
Result
.
error
(
"密码不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
// 密码校验
if
(!
userRegisterBO
.
getPassword
().
equals
(
userRegisterBO
.
getRepassword
()))
{
return
Result
.
error
(
"2次密码不一致"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userRegisterBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 验证码校验
@Autowired
private
IFeignSys
bossSys
;
@Autowired
private
PlatformDao
platformDao
;
@Autowired
private
UserDao
userDao
;
@Autowired
private
UserExtDao
userExtDao
;
@Autowired
private
SendSmsLogDao
sendSmsLogDao
;
@Autowired
private
UserLogLoginDao
userLogLoginDao
;
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
// RSA公钥
private
final
String
publicKey
=
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzBzD+Sgi5z+zq8P/qMimssuozcjdx4pBu2U2OKf6bDdQEKmSB1KXCheG2m19+xnerIZ22fr8nHc0r1qIKIUrJ0UWU8qXkANe4u0wW0V52BsW6H02Jmc1mFjrYcOCpToVFGvLm17AgP6tNBAiTjiiBc0V+prAZ9ixrC5aPsI4gAwIDAQAB"
;
@Transactional
public
Result
<
UserLoginDTO
>
register
(
UserRegisterBO
userRegisterBO
)
{
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getPassword
()))
{
return
Result
.
error
(
"密码不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userRegisterBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
// 密码校验
if
(!
userRegisterBO
.
getPassword
().
equals
(
userRegisterBO
.
getRepassword
()))
{
return
Result
.
error
(
"2次密码不一致"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userRegisterBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 验证码校验
// String redisSmsCode = redisTemplate.opsForValue().get(platform.getClientId() + userRegisterBO.getMobile());
// if (StringUtils.isEmpty(redisSmsCode)) {
// return Result.error("请输入验证码");
...
...
@@ -90,257 +96,261 @@ public class ApiUserInfoBiz extends BaseBiz {
// return Result.error("验证码不正确,请重新输入");
// }
// 手机号重复校验
User
user
=
userDao
.
getByMobile
(
userRegisterBO
.
getMobile
());
if
(
null
!=
user
)
{
return
Result
.
error
(
"该手机号已经注册,请更换手机号"
);
}
// 手机号重复校验
User
user
=
userDao
.
getByMobile
(
userRegisterBO
.
getMobile
());
if
(
null
!=
user
)
{
return
Result
.
error
(
"该手机号已经注册,请更换手机号"
);
}
// 用户注册
user
=
register
(
userRegisterBO
.
getMobile
(),
userRegisterBO
.
getPassword
(),
platform
.
getClientId
());
// 用户注册
user
=
register
(
userRegisterBO
.
getMobile
(),
userRegisterBO
.
getPassword
(),
platform
.
getClientId
());
// 同步数据到演示环境
try
{
String
post
=
HttpUtil
.
post
(
"https://demo.edu.roncoo.net/gateway/user/api/user/register"
,
JSONUtil
.
toJSONString
(
userRegisterBO
));
// 密码加密
RSA
rsa
=
new
RSA
(
null
,
publicKey
);
userRegisterBO
.
setPassword
(
rsa
.
encryptBase64
(
userRegisterBO
.
getPassword
(),
KeyType
.
PublicKey
));
userRegisterBO
.
setRepassword
(
rsa
.
encryptBase64
(
userRegisterBO
.
getRepassword
(),
KeyType
.
PublicKey
));
String
post
=
HttpUtil
.
post
(
"http://dev.school.roncoos.com/gateway/user/api/user/register"
,
JSONUtil
.
toJsonStr
(
userRegisterBO
));
logger
.
warn
(
"-----------------同步注册"
+
post
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
info
(
"同步数据异常:{}"
,
e
.
getMessage
());
}
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
return
Result
.
success
(
dto
);
}
public
Result
<
UserLoginDTO
>
loginPassword
(
UserLoginPasswordBO
userLoginPasswordBO
)
{
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getPassword
()))
{
return
Result
.
error
(
"密码不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userLoginPasswordBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 密码错误次数校验
// 用户校验
User
user
=
userDao
.
getByMobile
(
userLoginPasswordBO
.
getMobile
());
if
(
null
==
user
)
{
return
Result
.
error
(
"账号或者密码不正确"
);
}
// 密码校验
if
(!
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
userLoginPasswordBO
.
getPassword
()).
equals
(
user
.
getMobilePsw
()))
{
loginLog
(
user
.
getUserNo
(),
userLoginPasswordBO
.
getClientId
(),
LoginStatusEnum
.
FAIL
,
userLoginPasswordBO
.
getIp
());
// 放入缓存,错误次数+1
return
Result
.
error
(
"账号或者密码不正确"
);
}
// 登录日志
loginLog
(
user
.
getUserNo
(),
userLoginPasswordBO
.
getClientId
(),
LoginStatusEnum
.
SUCCESS
,
userLoginPasswordBO
.
getIp
());
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
// 登录成功,存入缓存,单点登录使用
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(),
// 1, TimeUnit.DAYS);
return
Result
.
success
(
dto
);
}
public
Result
<
UserLoginDTO
>
loginCode
(
UserLoginCodeBO
userLoginCodeBO
)
{
if
(
StringUtils
.
isEmpty
(
userLoginCodeBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginCodeBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号码不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userLoginCodeBO
.
getClientId
());
if
(
ObjectUtil
.
isNull
(
platform
))
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 登录错误次数的校验
// 验证码校验
String
redisSmsCode
=
redisTemplate
.
opsForValue
().
get
(
platform
.
getClientId
()
+
userLoginCodeBO
.
getMobile
());
if
(
StringUtils
.
isEmpty
(
redisSmsCode
))
{
return
Result
.
error
(
"验证码已经过期,请重新获取"
);
}
User
user
=
userDao
.
getByMobile
(
userLoginCodeBO
.
getMobile
());
if
(
null
==
user
)
{
return
Result
.
error
(
"该用户不存在"
);
}
if
(!
redisSmsCode
.
equals
(
userLoginCodeBO
.
getCode
()))
{
loginLog
(
user
.
getUserNo
(),
userLoginCodeBO
.
getClientId
(),
LoginStatusEnum
.
FAIL
,
userLoginCodeBO
.
getIp
());
// 缓存控制错误次数
return
Result
.
error
(
"验证码不正确,重新输入"
);
}
// 清空缓存
redisTemplate
.
delete
(
platform
.
getClientId
()
+
userLoginCodeBO
.
getMobile
());
// 登录日志
loginLog
(
user
.
getUserNo
(),
userLoginCodeBO
.
getClientId
(),
LoginStatusEnum
.
SUCCESS
,
userLoginCodeBO
.
getIp
());
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
// 登录成功,存入缓存,单点登录使用
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(),
// 1, TimeUnit.DAYS);
return
Result
.
success
(
dto
);
}
public
Result
<
String
>
sendCode
(
UserSendCodeBO
userSendCodeBO
)
{
if
(
StringUtils
.
isEmpty
(
userSendCodeBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(!
Pattern
.
compile
(
Constants
.
REGEX_MOBILE
).
matcher
(
userSendCodeBO
.
getMobile
()).
matches
())
{
return
Result
.
error
(
"手机号码格式不正确"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userSendCodeBO
.
getClientId
());
if
(
ObjectUtil
.
isNull
(
platform
))
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
SysVO
sys
=
bossSys
.
getSys
();
if
(
ObjectUtil
.
isNull
(
sys
))
{
return
Result
.
error
(
"找不到系统配置信息"
);
}
// 创建日志实例
SendSmsLog
sendSmsLog
=
new
SendSmsLog
();
sendSmsLog
.
setMobile
(
userSendCodeBO
.
getMobile
());
sendSmsLog
.
setTemplate
(
sys
.
getSmsCode
());
// 随机生成验证码
sendSmsLog
.
setSmsCode
(
RandomUtil
.
randomNumbers
(
6
));
try
{
// 发送验证码
boolean
result
=
AliyunUtil
.
sendMsg
(
userSendCodeBO
.
getMobile
(),
sendSmsLog
.
getSmsCode
(),
BeanUtil
.
copyProperties
(
sys
,
Aliyun
.
class
));
// 发送成功,验证码存入缓存:5分钟有效
if
(
result
)
{
redisTemplate
.
opsForValue
().
set
(
userSendCodeBO
.
getClientId
()
+
userSendCodeBO
.
getMobile
(),
sendSmsLog
.
getSmsCode
(),
5
,
TimeUnit
.
MINUTES
);
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
SUCCESS
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
return
Result
.
success
(
"发送成功"
);
}
// 发送失败
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
FAIL
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
throw
new
BaseException
(
"发送失败"
);
}
catch
(
ClientException
e
)
{
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
FAIL
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
logger
.
error
(
"发送失败,原因={}"
,
e
.
getErrMsg
());
return
Result
.
error
(
"发送失败"
);
}
}
private
User
register
(
String
mobile
,
String
password
,
String
clientId
)
{
// 用户基本信息
User
user
=
new
User
();
user
.
setUserNo
(
NOUtil
.
getUserNo
());
user
.
setMobile
(
mobile
);
user
.
setMobileSalt
(
StrUtil
.
get32UUID
());
user
.
setMobilePsw
(
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
password
));
user
.
setUserSource
(
clientId
);
userDao
.
save
(
user
);
// 用户其他信息
UserExt
userExt
=
new
UserExt
();
userExt
.
setUserNo
(
user
.
getUserNo
());
userExt
.
setUserType
(
UserTypeEnum
.
USER
.
getCode
());
userExt
.
setMobile
(
user
.
getMobile
());
userExtDao
.
save
(
userExt
);
return
user
;
}
private
void
loginLog
(
Long
userNo
,
String
clientId
,
LoginStatusEnum
status
,
String
ip
)
{
UserLogLogin
record
=
new
UserLogLogin
();
record
.
setUserNo
(
userNo
);
record
.
setClientId
(
clientId
);
record
.
setLoginStatus
(
status
.
getCode
());
record
.
setLoginIp
(
ip
);
userLogLoginDao
.
save
(
record
);
}
public
Result
<
Integer
>
updatePassword
(
UserUpdateBO
userUpdateBO
)
{
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号为空,请重试"
);
}
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getCode
()))
{
return
Result
.
error
(
"验证码不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userUpdateBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
String
redisCode
=
redisTemplate
.
opsForValue
().
get
(
platform
.
getClientId
()
+
userUpdateBO
.
getMobile
());
if
(
StringUtils
.
isEmpty
(
redisCode
))
{
return
Result
.
error
(
"请输入验证码"
);
}
if
(!
userUpdateBO
.
getCode
().
equals
(
redisCode
))
{
return
Result
.
error
(
"验证码匹配不正确"
);
}
// 手机号去空处理
String
mobile
=
userUpdateBO
.
getMobile
().
replaceAll
(
" +"
,
""
);
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getConfirmPassword
()))
{
return
Result
.
error
(
"新登录密码为空,请重试"
);
}
if
(!
userUpdateBO
.
getNewPassword
().
equals
(
userUpdateBO
.
getConfirmPassword
()))
{
return
Result
.
error
(
"密码输入不一致,请重试"
);
}
User
user
=
userDao
.
getByMobile
(
mobile
);
if
(
ObjectUtil
.
isNull
(
user
))
{
return
Result
.
error
(
"没找到用户信息,请重试"
);
}
if
(
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
userUpdateBO
.
getNewPassword
()).
equals
(
user
.
getMobilePsw
()))
{
return
Result
.
error
(
"输入的密码与原密码一致,请重试"
);
}
// 更新密码
User
bean
=
new
User
();
bean
.
setId
(
user
.
getId
());
bean
.
setMobileSalt
(
StrUtil
.
get32UUID
());
bean
.
setMobilePsw
(
DigestUtil
.
sha1Hex
(
bean
.
getMobileSalt
()
+
userUpdateBO
.
getNewPassword
()));
int
result
=
userDao
.
updateById
(
bean
);
return
result
==
1
?
Result
.
success
(
result
)
:
Result
.
error
(
ResultEnum
.
USER_UPDATE_FAIL
.
getDesc
());
}
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
return
Result
.
success
(
dto
);
}
public
Result
<
UserLoginDTO
>
loginPassword
(
UserLoginPasswordBO
userLoginPasswordBO
)
{
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginPasswordBO
.
getPassword
()))
{
return
Result
.
error
(
"密码不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userLoginPasswordBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 密码错误次数校验
// 用户校验
User
user
=
userDao
.
getByMobile
(
userLoginPasswordBO
.
getMobile
());
if
(
null
==
user
)
{
return
Result
.
error
(
"账号或者密码不正确"
);
}
// 密码校验
if
(!
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
userLoginPasswordBO
.
getPassword
()).
equals
(
user
.
getMobilePsw
()))
{
loginLog
(
user
.
getUserNo
(),
userLoginPasswordBO
.
getClientId
(),
LoginStatusEnum
.
FAIL
,
userLoginPasswordBO
.
getIp
());
// 放入缓存,错误次数+1
return
Result
.
error
(
"账号或者密码不正确"
);
}
// 登录日志
loginLog
(
user
.
getUserNo
(),
userLoginPasswordBO
.
getClientId
(),
LoginStatusEnum
.
SUCCESS
,
userLoginPasswordBO
.
getIp
());
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
// 登录成功,存入缓存,单点登录使用
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(),
// 1, TimeUnit.DAYS);
return
Result
.
success
(
dto
);
}
public
Result
<
UserLoginDTO
>
loginCode
(
UserLoginCodeBO
userLoginCodeBO
)
{
if
(
StringUtils
.
isEmpty
(
userLoginCodeBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userLoginCodeBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号码不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userLoginCodeBO
.
getClientId
());
if
(
ObjectUtil
.
isNull
(
platform
))
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
// 登录错误次数的校验
// 验证码校验
String
redisSmsCode
=
redisTemplate
.
opsForValue
().
get
(
platform
.
getClientId
()
+
userLoginCodeBO
.
getMobile
());
if
(
StringUtils
.
isEmpty
(
redisSmsCode
))
{
return
Result
.
error
(
"验证码已经过期,请重新获取"
);
}
User
user
=
userDao
.
getByMobile
(
userLoginCodeBO
.
getMobile
());
if
(
null
==
user
)
{
return
Result
.
error
(
"该用户不存在"
);
}
if
(!
redisSmsCode
.
equals
(
userLoginCodeBO
.
getCode
()))
{
loginLog
(
user
.
getUserNo
(),
userLoginCodeBO
.
getClientId
(),
LoginStatusEnum
.
FAIL
,
userLoginCodeBO
.
getIp
());
// 缓存控制错误次数
return
Result
.
error
(
"验证码不正确,重新输入"
);
}
// 清空缓存
redisTemplate
.
delete
(
platform
.
getClientId
()
+
userLoginCodeBO
.
getMobile
());
// 登录日志
loginLog
(
user
.
getUserNo
(),
userLoginCodeBO
.
getClientId
(),
LoginStatusEnum
.
SUCCESS
,
userLoginCodeBO
.
getIp
());
UserLoginDTO
dto
=
new
UserLoginDTO
();
dto
.
setUserNo
(
user
.
getUserNo
());
dto
.
setMobile
(
user
.
getMobile
());
dto
.
setToken
(
JWTUtil
.
create
(
user
.
getUserNo
(),
JWTUtil
.
DATE
));
// 登录成功,存入缓存,单点登录使用
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(),
// 1, TimeUnit.DAYS);
return
Result
.
success
(
dto
);
}
public
Result
<
String
>
sendCode
(
UserSendCodeBO
userSendCodeBO
)
{
if
(
StringUtils
.
isEmpty
(
userSendCodeBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
if
(!
Pattern
.
compile
(
Constants
.
REGEX_MOBILE
).
matcher
(
userSendCodeBO
.
getMobile
()).
matches
())
{
return
Result
.
error
(
"手机号码格式不正确"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userSendCodeBO
.
getClientId
());
if
(
ObjectUtil
.
isNull
(
platform
))
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
SysVO
sys
=
bossSys
.
getSys
();
if
(
ObjectUtil
.
isNull
(
sys
))
{
return
Result
.
error
(
"找不到系统配置信息"
);
}
// 创建日志实例
SendSmsLog
sendSmsLog
=
new
SendSmsLog
();
sendSmsLog
.
setMobile
(
userSendCodeBO
.
getMobile
());
sendSmsLog
.
setTemplate
(
sys
.
getSmsCode
());
// 随机生成验证码
sendSmsLog
.
setSmsCode
(
RandomUtil
.
randomNumbers
(
6
));
try
{
// 发送验证码
boolean
result
=
AliyunUtil
.
sendMsg
(
userSendCodeBO
.
getMobile
(),
sendSmsLog
.
getSmsCode
(),
BeanUtil
.
copyProperties
(
sys
,
Aliyun
.
class
));
// 发送成功,验证码存入缓存:5分钟有效
if
(
result
)
{
redisTemplate
.
opsForValue
().
set
(
userSendCodeBO
.
getClientId
()
+
userSendCodeBO
.
getMobile
(),
sendSmsLog
.
getSmsCode
(),
5
,
TimeUnit
.
MINUTES
);
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
SUCCESS
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
return
Result
.
success
(
"发送成功"
);
}
// 发送失败
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
FAIL
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
throw
new
BaseException
(
"发送失败"
);
}
catch
(
ClientException
e
)
{
sendSmsLog
.
setIsSuccess
(
IsSuccessEnum
.
FAIL
.
getCode
());
sendSmsLogDao
.
save
(
sendSmsLog
);
logger
.
error
(
"发送失败,原因={}"
,
e
.
getErrMsg
());
return
Result
.
error
(
"发送失败"
);
}
}
private
User
register
(
String
mobile
,
String
password
,
String
clientId
)
{
// 用户基本信息
User
user
=
new
User
();
user
.
setUserNo
(
NOUtil
.
getUserNo
());
user
.
setMobile
(
mobile
);
user
.
setMobileSalt
(
StrUtil
.
get32UUID
());
user
.
setMobilePsw
(
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
password
));
user
.
setUserSource
(
clientId
);
userDao
.
save
(
user
);
// 用户其他信息
UserExt
userExt
=
new
UserExt
();
userExt
.
setUserNo
(
user
.
getUserNo
());
userExt
.
setUserType
(
UserTypeEnum
.
USER
.
getCode
());
userExt
.
setMobile
(
user
.
getMobile
());
userExtDao
.
save
(
userExt
);
return
user
;
}
private
void
loginLog
(
Long
userNo
,
String
clientId
,
LoginStatusEnum
status
,
String
ip
)
{
UserLogLogin
record
=
new
UserLogLogin
();
record
.
setUserNo
(
userNo
);
record
.
setClientId
(
clientId
);
record
.
setLoginStatus
(
status
.
getCode
());
record
.
setLoginIp
(
ip
);
userLogLoginDao
.
save
(
record
);
}
public
Result
<
Integer
>
updatePassword
(
UserUpdateBO
userUpdateBO
)
{
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getMobile
()))
{
return
Result
.
error
(
"手机号为空,请重试"
);
}
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getCode
()))
{
return
Result
.
error
(
"验证码不能为空"
);
}
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getClientId
()))
{
return
Result
.
error
(
"clientId不能为空"
);
}
Platform
platform
=
platformDao
.
getByClientId
(
userUpdateBO
.
getClientId
());
if
(
null
==
platform
)
{
return
Result
.
error
(
"该平台不存在"
);
}
if
(!
StatusIdEnum
.
YES
.
getCode
().
equals
(
platform
.
getStatusId
()))
{
return
Result
.
error
(
"该平台状态异常,请联系管理员"
);
}
String
redisCode
=
redisTemplate
.
opsForValue
().
get
(
platform
.
getClientId
()
+
userUpdateBO
.
getMobile
());
if
(
StringUtils
.
isEmpty
(
redisCode
))
{
return
Result
.
error
(
"请输入验证码"
);
}
if
(!
userUpdateBO
.
getCode
().
equals
(
redisCode
))
{
return
Result
.
error
(
"验证码匹配不正确"
);
}
// 手机号去空处理
String
mobile
=
userUpdateBO
.
getMobile
().
replaceAll
(
" +"
,
""
);
if
(
StringUtils
.
isEmpty
(
userUpdateBO
.
getConfirmPassword
()))
{
return
Result
.
error
(
"新登录密码为空,请重试"
);
}
if
(!
userUpdateBO
.
getNewPassword
().
equals
(
userUpdateBO
.
getConfirmPassword
()))
{
return
Result
.
error
(
"密码输入不一致,请重试"
);
}
User
user
=
userDao
.
getByMobile
(
mobile
);
if
(
ObjectUtil
.
isNull
(
user
))
{
return
Result
.
error
(
"没找到用户信息,请重试"
);
}
if
(
DigestUtil
.
sha1Hex
(
user
.
getMobileSalt
()
+
userUpdateBO
.
getNewPassword
()).
equals
(
user
.
getMobilePsw
()))
{
return
Result
.
error
(
"输入的密码与原密码一致,请重试"
);
}
// 更新密码
User
bean
=
new
User
();
bean
.
setId
(
user
.
getId
());
bean
.
setMobileSalt
(
StrUtil
.
get32UUID
());
bean
.
setMobilePsw
(
DigestUtil
.
sha1Hex
(
bean
.
getMobileSalt
()
+
userUpdateBO
.
getNewPassword
()));
int
result
=
userDao
.
updateById
(
bean
);
return
result
==
1
?
Result
.
success
(
result
)
:
Result
.
error
(
ResultEnum
.
USER_UPDATE_FAIL
.
getDesc
());
}
}
roncoo-education-util/pom.xml
浏览文件 @
6c8da748
...
...
@@ -47,6 +47,12 @@
<artifactId>
hutool
</artifactId>
</dependency>
<!-- hutool -->
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
</dependency>
<!-- jwt -->
<dependency>
<groupId>
com.auth0
</groupId>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录