Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-cr20g
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
dsk-cr20g
Commits
b679eb19
Commit
b679eb19
authored
Sep 07, 2023
by
tanyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复短信登录没有默认租户问题
parent
7127b465
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
41 deletions
+79
-41
SysLoginController.java
...ava/com/dsk/web/controller/system/SysLoginController.java
+38
-29
messages_zh_CN.properties
dsk-admin/src/main/resources/i18n/messages_zh_CN.properties
+1
-1
SysLoginService.java
...src/main/java/com/dsk/system/service/SysLoginService.java
+40
-11
No files found.
dsk-admin/src/main/java/com/dsk/web/controller/system/SysLoginController.java
View file @
b679eb19
...
@@ -3,6 +3,7 @@ package com.dsk.web.controller.system;
...
@@ -3,6 +3,7 @@ package com.dsk.web.controller.system;
import
cn.dev33.satoken.annotation.SaCheckLogin
;
import
cn.dev33.satoken.annotation.SaCheckLogin
;
import
cn.dev33.satoken.annotation.SaIgnore
;
import
cn.dev33.satoken.annotation.SaIgnore
;
import
cn.dev33.satoken.stp.StpUtil
;
import
cn.dev33.satoken.stp.StpUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.lang.RegexPool
;
import
cn.hutool.core.lang.RegexPool
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
...
@@ -80,6 +81,38 @@ public class SysLoginController {
...
@@ -80,6 +81,38 @@ public class SysLoginController {
// /**
// * 发送短信验证码
// *
// * @param phones 电话号
// * @param templateId 模板ID
// */
// @SaIgnore
// @GetMapping("/send/sms/code")
// public R<Object> sendAliyun(String phones, String templateId) {
// LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
// map.put("code", RandomUtil.randomNumbers(4));
// SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
// SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
// return R.ok(smsResponse);
// }
/**
* 短信登录
*
* @param smsLoginBody 登录信息
* @return 结果
*/
@SaIgnore
@PostMapping
(
"/smsLogin"
)
public
R
<
LoginVo
>
smsLogin
(
@Validated
@RequestBody
SmsLoginBody
smsLoginBody
)
{
// 生成令牌
LoginVo
loginVo
=
loginService
.
smsLogin
(
smsLoginBody
.
getPhonenumber
(),
smsLoginBody
.
getSmsCode
());
return
R
.
ok
(
loginVo
);
}
/**
/**
* 动态切换租户
* 动态切换租户
*
*
...
@@ -118,6 +151,11 @@ public class SysLoginController {
...
@@ -118,6 +151,11 @@ public class SysLoginController {
return
R
.
ok
(
new
ArrayList
<>());
return
R
.
ok
(
new
ArrayList
<>());
}
}
List
<
SysTenantVo
>
tenantList
=
loginService
.
tenantListByAccount
(
phone
);
List
<
SysTenantVo
>
tenantList
=
loginService
.
tenantListByAccount
(
phone
);
if
(
CollectionUtil
.
isNotEmpty
(
tenantList
)){
for
(
SysTenantVo
sysTenantVo
:
tenantList
)
{
sysTenantVo
.
setCompanyName
(
""
);
}
}
return
R
.
ok
(
tenantList
);
return
R
.
ok
(
tenantList
);
}
}
...
@@ -150,35 +188,6 @@ public class SysLoginController {
...
@@ -150,35 +188,6 @@ public class SysLoginController {
return
R
.
ok
(
MapUtil
.
of
(
"tenantId"
,
defaultTenant
));
return
R
.
ok
(
MapUtil
.
of
(
"tenantId"
,
defaultTenant
));
}
}
/**
* 发送短信验证码
*
* @param phones 电话号
* @param templateId 模板ID
*/
@SaIgnore
@GetMapping
(
"/send/sms/code"
)
public
R
<
Object
>
sendAliyun
(
String
phones
,
String
templateId
)
{
LinkedHashMap
<
String
,
String
>
map
=
new
LinkedHashMap
<>(
1
);
map
.
put
(
"code"
,
RandomUtil
.
randomNumbers
(
4
));
SmsBlend
smsBlend
=
SmsFactory
.
createSmsBlend
(
SupplierType
.
ALIBABA
);
SmsResponse
smsResponse
=
smsBlend
.
sendMessage
(
phones
,
templateId
,
map
);
return
R
.
ok
(
smsResponse
);
}
/**
* 短信登录
*
* @param smsLoginBody 登录信息
* @return 结果
*/
@SaIgnore
@PostMapping
(
"/smsLogin"
)
public
R
<
LoginVo
>
smsLogin
(
@Validated
@RequestBody
SmsLoginBody
smsLoginBody
)
{
// 生成令牌
LoginVo
loginVo
=
loginService
.
smsLogin
(
smsLoginBody
.
getPhonenumber
(),
smsLoginBody
.
getSmsCode
());
return
R
.
ok
(
loginVo
);
}
/**
/**
* 邮件登录
* 邮件登录
*
*
...
...
dsk-admin/src/main/resources/i18n/messages_zh_CN.properties
View file @
b679eb19
...
@@ -50,5 +50,5 @@ xcx.code.not.blank=\u5C0F\u7A0B\u5E8Fcode\u4E0D\u80FD\u4E3A\u7A7A
...
@@ -50,5 +50,5 @@ xcx.code.not.blank=\u5C0F\u7A0B\u5E8Fcode\u4E0D\u80FD\u4E3A\u7A7A
##\u79DF\u6237
##\u79DF\u6237
company.number.not.blank
=
\u
4F01
\u
4E1A
\u
7F16
\u
53F7
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
company.number.not.blank
=
\u
4F01
\u
4E1A
\u
7F16
\u
53F7
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
company.not.exists
=
\u
5BF9
\u
4E0D
\u
8D77,
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
4E0D
\u
5B58
\u5728\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
company.not.exists
=
\u
5BF9
\u
4E0D
\u
8D77,
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
4E0D
\u
5B58
\u5728\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
company.blocked
=
\u
5BF9
\u
4E0D
\u
8D77
\u
FF0C
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
5DF2
\u
7981
\u7528\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
company.blocked
=
\u
5BF9
\u
4E0D
\u
8D77
\u
FF0C
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
5DF2
\u
505C
\u7528\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
company.expired
=
\u
5BF9
\u
4E0D
\u
8D77
\u
FF0C
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
5DF2
\u
8FC7
\u
671F
\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
company.expired
=
\u
5BF9
\u
4E0D
\u
8D77
\u
FF0C
\u
60A8
\u7684\u
4F01
\u
4E1A
\u
5DF2
\u
8FC7
\u
671F
\u
FF0C
\u
8BF7
\u8054\u
7CFB
\u
7BA1
\u7406\u5458
\ No newline at end of file
dsk-system/src/main/java/com/dsk/system/service/SysLoginService.java
View file @
b679eb19
...
@@ -100,6 +100,7 @@ public class SysLoginService {
...
@@ -100,6 +100,7 @@ public class SysLoginService {
String
defaultTenantId
=
RedisUtils
.
getCacheObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
username
);
String
defaultTenantId
=
RedisUtils
.
getCacheObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
username
);
log
.
info
(
"登录用户:{} 获取缓存默认租户:"
+
tenantId
,
username
);
log
.
info
(
"登录用户:{} 获取缓存默认租户:"
+
tenantId
,
username
);
if
(
StrUtil
.
isNotBlank
(
defaultTenantId
)){
if
(
StrUtil
.
isNotBlank
(
defaultTenantId
)){
defaultTenantId
=
checkDefaultTenant
(
defaultTenantId
,
username
);
tenantId
=
defaultTenantId
;
tenantId
=
defaultTenantId
;
}
}
}
}
...
@@ -189,13 +190,14 @@ public class SysLoginService {
...
@@ -189,13 +190,14 @@ public class SysLoginService {
public
LoginVo
smsLogin
(
String
username
,
String
smsCode
)
{
public
LoginVo
smsLogin
(
String
username
,
String
smsCode
)
{
String
tenantId
=
null
;
String
tenantId
=
null
;
// if(ReUtil.isMatch(RegexPool.MOBILE, username)) {
if
(
ReUtil
.
isMatch
(
RegexPool
.
MOBILE
,
username
))
{
// String defaultTenantId = RedisUtils.getCacheObject(GlobalConstants.PHONE_DEFAULT_TENANT + username);
String
defaultTenantId
=
RedisUtils
.
getCacheObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
username
);
// log.info("登录用户:{} 获取缓存默认租户:"+tenantId, username);
log
.
info
(
"登录用户:{} 获取缓存默认租户:"
+
tenantId
,
username
);
// if(StrUtil.isNotBlank(defaultTenantId)){
if
(
StrUtil
.
isNotBlank
(
defaultTenantId
)){
// tenantId=defaultTenantId;
defaultTenantId
=
checkDefaultTenant
(
defaultTenantId
,
username
);
// }
tenantId
=
defaultTenantId
;
// }
}
}
//查询手机号绑定的所有用户
//查询手机号绑定的所有用户
if
(
StrUtil
.
isEmpty
(
tenantId
))
{
if
(
StrUtil
.
isEmpty
(
tenantId
))
{
...
@@ -231,7 +233,7 @@ public class SysLoginService {
...
@@ -231,7 +233,7 @@ public class SysLoginService {
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
SysUser
user
=
loadUserByUsername
(
username
);
SysUser
user
=
loadUserByUsername
(
username
);
checkLogin
(
LoginType
.
PASSWORD
,
username
,
()
->
!
validateSmsCode
(
username
,
smsCode
));
checkLogin
(
LoginType
.
SMS
,
username
,
()
->
!
validateSmsCode
(
username
,
smsCode
));
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
LoginUser
loginUser
=
buildLoginUser
(
user
);
LoginUser
loginUser
=
buildLoginUser
(
user
);
// 生成token
// 生成token
...
@@ -501,18 +503,45 @@ public class SysLoginService {
...
@@ -501,18 +503,45 @@ public class SysLoginService {
}
}
SysTenantVo
tenant
=
sysTenantService
.
queryByTenantId
(
tenantId
);
SysTenantVo
tenant
=
sysTenantService
.
queryByTenantId
(
tenantId
);
if
(
ObjectUtil
.
isNull
(
tenant
))
{
if
(
ObjectUtil
.
isNull
(
tenant
))
{
log
.
info
(
"登录
租户:{} 不存在."
,
tenantId
);
log
.
info
(
"登录
企业:{} 不存在."
,
tenant
.
getCompanyName
()
);
throw
new
TenantException
(
"company.not.exists"
);
throw
new
TenantException
(
"company.not.exists"
);
}
else
if
(
TenantStatus
.
DISABLE
.
getCode
().
equals
(
tenant
.
getStatus
()))
{
}
else
if
(
TenantStatus
.
DISABLE
.
getCode
().
equals
(
tenant
.
getStatus
()))
{
log
.
info
(
"登录
租户:{} 已被停用."
,
tenantId
);
log
.
info
(
"登录
企业:{} 已被停用."
,
tenant
.
getCompanyName
()
);
throw
new
TenantException
(
"company.blocked"
);
throw
new
TenantException
(
"company.blocked"
);
}
else
if
(
ObjectUtil
.
isNotNull
(
tenant
.
getExpireTime
())
}
else
if
(
ObjectUtil
.
isNotNull
(
tenant
.
getExpireTime
())
&&
new
Date
().
after
(
tenant
.
getExpireTime
()))
{
&&
new
Date
().
after
(
tenant
.
getExpireTime
()))
{
log
.
info
(
"登录
租户:{} 已超过有效期."
,
tenantId
);
log
.
info
(
"登录
企业:{} 已超过有效期."
,
tenant
.
getCompanyName
()
);
throw
new
TenantException
(
"company.expired"
);
throw
new
TenantException
(
"company.expired"
);
}
}
}
}
public
String
checkDefaultTenant
(
String
tenantId
,
String
phoneNumber
)
{
if
(!
TenantHelper
.
isEnable
())
{
return
null
;
}
if
(
TenantConstants
.
DEFAULT_TENANT_ID
.
equals
(
tenantId
))
{
return
null
;
}
SysTenantVo
tenant
=
sysTenantService
.
queryByTenantId
(
tenantId
);
if
(
ObjectUtil
.
isNull
(
tenant
))
{
log
.
info
(
"登录企业:{} 不存在."
,
tenant
.
getCompanyName
());
RedisUtils
.
deleteObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
phoneNumber
);
return
null
;
}
else
if
(
TenantStatus
.
DISABLE
.
getCode
().
equals
(
tenant
.
getStatus
()))
{
log
.
info
(
"登录企业:{} 已被停用."
,
tenant
.
getCompanyName
());
RedisUtils
.
deleteObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
phoneNumber
);
return
null
;
}
else
if
(
ObjectUtil
.
isNotNull
(
tenant
.
getExpireTime
())
&&
new
Date
().
after
(
tenant
.
getExpireTime
()))
{
log
.
info
(
"登录企业:{} 已超过有效期."
,
tenant
.
getCompanyName
());
RedisUtils
.
deleteObject
(
GlobalConstants
.
PHONE_DEFAULT_TENANT
+
phoneNumber
);
return
null
;
}
return
tenantId
;
}
public
List
<
SysTenantVo
>
tenantListByAccount
(
String
username
)
{
public
List
<
SysTenantVo
>
tenantListByAccount
(
String
username
)
{
return
TenantHelper
.
ignore
(()
->
sysTenantService
.
selectTenantList
(
username
));
return
TenantHelper
.
ignore
(()
->
sysTenantService
.
selectTenantList
(
username
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment