Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 2f7c27ff
由
zshaohui
编写于
2025-09-19 13:38:37 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.增加扫码登录功能
1 个父辈
75a65b5a
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
120 行增加
和
3 行删除
src/main/java/com/neotel/smfcore/common/init/DataInitManager.java
src/main/java/com/neotel/smfcore/common/utils/Constants.java
src/main/java/com/neotel/smfcore/common/utils/UserCodeUtil.java
src/main/java/com/neotel/smfcore/core/system/rest/SettingsController.java
src/main/java/com/neotel/smfcore/core/system/rest/bean/dto/SysSettingsDto.java
src/main/java/com/neotel/smfcore/security/rest/AuthorizationController.java
src/main/java/com/neotel/smfcore/security/rest/UserController.java
src/main/java/com/neotel/smfcore/security/service/po/User.java
src/main/java/com/neotel/smfcore/common/init/DataInitManager.java
查看文件 @
2f7c27f
...
...
@@ -100,7 +100,7 @@ public class DataInitManager {
operator
=
roleManager
.
save
(
operator
);
log
.
info
(
"创建默认角色:"
+
operator
.
toString
());
admin
=
new
User
(
userName
,
"admin@neotel.tech"
,
"zh-CN"
,
role
.
getId
(),
"$2a$10$Egp1/gvFlt7zhlXVfEFw4OfWQCGPw0ClmMcc6FjTnvXNRVf9zdMRa"
,
true
,
true
,
new
Date
(),
groupIds
,
""
,
""
);
admin
=
new
User
(
userName
,
"admin@neotel.tech"
,
"zh-CN"
,
role
.
getId
(),
"$2a$10$Egp1/gvFlt7zhlXVfEFw4OfWQCGPw0ClmMcc6FjTnvXNRVf9zdMRa"
,
true
,
true
,
new
Date
(),
groupIds
,
""
,
""
,
""
);
admin
=
userManager
.
save
(
admin
);
log
.
info
(
"创建默认用户:"
+
admin
.
toString
());
...
...
src/main/java/com/neotel/smfcore/common/utils/Constants.java
查看文件 @
2f7c27f
...
...
@@ -218,4 +218,9 @@ public class Constants {
*/
public
static
final
String
Cache_DefLanguage
=
"Cache_DefLanguage"
;
/**
* 是否扫描登录
*/
public
static
final
String
Cache_QRCodeLogin
=
"Cache_QRCodeLogin"
;
}
src/main/java/com/neotel/smfcore/common/utils/UserCodeUtil.java
查看文件 @
2f7c27f
...
...
@@ -111,7 +111,7 @@ public class UserCodeUtil {
String
langu
=
""
;
String
roleId
=
""
;
User
user
=
new
User
(
username
,
email
,
langu
,
roleId
,
""
,
true
,
false
,
new
Date
(),
new
HashSet
<>(),
""
,
""
);
,
false
,
new
Date
(),
new
HashSet
<>(),
""
,
""
,
""
);
user
.
setId
(
id
);
user
.
setCreateDate
(
createData
);
list
.
add
(
user
);
...
...
src/main/java/com/neotel/smfcore/core/system/rest/SettingsController.java
查看文件 @
2f7c27f
...
...
@@ -94,6 +94,11 @@ public class SettingsController {
defLanguage
=
"zh"
;
}
dto
.
setDefLanguage
(
defLanguage
);
Boolean
QRCodeLogin
=
dataCache
.
getCache
(
Constants
.
Cache_QRCodeLogin
);
if
(
QRCodeLogin
==
null
){
QRCodeLogin
=
false
;
}
dto
.
setQRCodeLogin
(
QRCodeLogin
);
return
dto
;
}
...
...
@@ -109,10 +114,12 @@ public class SettingsController {
dataCache
.
updateCache
(
Constants
.
BACKUP_MONTH_KEY
,
sysSettingsDto
.
getBackUpMonth
());
dataCache
.
updateCache
(
Constants
.
CACHE_closeWorkOrder
,
sysSettingsDto
.
isCloseWorkOrder
());
dataCache
.
updateCache
(
Constants
.
Cache_DefLanguage
,
sysSettingsDto
.
getDefLanguage
());
dataCache
.
updateCache
(
Constants
.
Cache_QRCodeLogin
,
sysSettingsDto
.
isQRCodeLogin
());
log
.
info
(
"更改系统设置:stopout="
+
sysSettingsDto
.
isStopOut
()
+
",stopjob="
+
sysSettingsDto
.
isStartJob
()+
",sluggishDay="
+
sysSettingsDto
.
getSluggishDay
()
+
",expiresDay="
+
sysSettingsDto
.
getExpiresDay
()+
",capacityWarn="
+
sysSettingsDto
.
getCapacityWarn
()+
",backUpMonth="
+
sysSettingsDto
.
getBackUpMonth
()
+
",缺料不自动关闭工单="
+
sysSettingsDto
.
isCloseWorkOrder
()
+
"默认语言为:"
+
sysSettingsDto
.
getDefLanguage
());
+
"默认语言为:"
+
sysSettingsDto
.
getDefLanguage
()
+
"是否扫码登录:"
+
sysSettingsDto
.
isQRCodeLogin
());
return
ResultBean
.
newOkResult
(
"保存成功"
);
}
...
...
@@ -334,4 +341,15 @@ public class SettingsController {
}
return
ResultBean
.
newOkResult
(
""
);
}
@ApiOperation
(
"判断是否扫码登录"
)
@GetMapping
(
"/QRCodeLogin"
)
@AnonymousAccess
public
ResultBean
QRCodeLogin
()
{
Boolean
QRCodeLogin
=
dataCache
.
getCache
(
Constants
.
Cache_QRCodeLogin
);
if
(
QRCodeLogin
==
null
){
QRCodeLogin
=
false
;
}
return
ResultBean
.
newOkResult
(
QRCodeLogin
);
}
}
src/main/java/com/neotel/smfcore/core/system/rest/bean/dto/SysSettingsDto.java
查看文件 @
2f7c27f
...
...
@@ -33,4 +33,7 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty
(
"默认语言"
)
private
String
defLanguage
=
"zh"
;
@ApiModelProperty
(
"是否扫码登录"
)
private
boolean
QRCodeLogin
=
false
;
}
src/main/java/com/neotel/smfcore/security/rest/AuthorizationController.java
查看文件 @
2f7c27f
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
neotel
.
smfcore
.
security
.
rest
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.utils.*
;
import
com.neotel.smfcore.core.api.SmfApi
;
import
com.neotel.smfcore.security.annotation.AnonymousDeleteMapping
;
...
...
@@ -28,6 +29,8 @@ import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import
com.neotel.smfcore.security.service.OnlineUserService
;
import
com.neotel.smfcore.security.rest.bean.dto.AuthUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.service.manager.IUserManager
;
import
com.neotel.smfcore.security.service.po.User
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -39,6 +42,8 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -70,6 +75,12 @@ public class AuthorizationController {
@Resource
private
LoginProperties
loginProperties
;
@Autowired
private
IUserManager
userManager
;
@Autowired
private
UserDetailsService
userDetailsService
;
@ApiOperation
(
"登录授权"
)
@AnonymousPostMapping
(
value
=
"/login"
)
public
ResponseEntity
<
Object
>
login
(
@Validated
@RequestBody
AuthUserDto
authUser
,
HttpServletRequest
request
)
throws
Exception
{
...
...
@@ -161,6 +172,60 @@ public class AuthorizationController {
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
@ApiOperation
(
"扫码登录授权"
)
@AnonymousPostMapping
(
value
=
"/QRCodeLogin"
)
public
ResponseEntity
<
Object
>
QRCodeLogin
(
@RequestBody
AuthUserDto
authUser
,
HttpServletRequest
request
)
throws
Exception
{
String
code
=
authUser
.
getCode
();
if
(
StringUtils
.
isEmpty
(
code
))
{
throw
new
ValidateException
(
"smfcore.valueCanotNull"
,
"{0}不能为空"
,
new
String
[]{
"code"
});
}
//取第一位是id信息
String
id
=
code
.
substring
(
0
,
code
.
indexOf
(
"-"
));
User
user
=
userManager
.
get
(
id
);
if
(
user
==
null
)
{
throw
new
ValidateException
(
"smfcore.valueNotExist"
,
"{0}[{1}]不存在"
,
new
String
[]{
"userId"
,
id
});
}
//判断与登录是否一致
String
loginCode
=
user
.
getLoginCode
();
if
(!
code
.
equals
(
loginCode
)){
throw
new
ValidateException
(
"smfcore.login.codeError"
,
"登录码[{0}]错误"
,
new
String
[]{
code
});
}
// 生成令牌与第三方系统获取令牌方式
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
user
.
getUsername
());
Authentication
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
null
,
userDetails
.
getAuthorities
());
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
String
token
=
tokenProvider
.
createToken
(
authentication
);
final
JwtUserDto
jwtUserDto
=
(
JwtUserDto
)
authentication
.
getPrincipal
();
// 保存在线信息
String
ip
=
StringUtils
.
getIp
(
request
);
String
browser
=
StringUtils
.
getBrowser
(
request
);
String
address
=
StringUtils
.
getCityInfo
(
ip
);
OnlineUserDto
onlineUserDto
=
null
;
try
{
long
seconds
=
onlineUserService
.
properties
.
getTokenValidityInSeconds
()
/
1000
;
Date
exTime
=
DateUtil
.
addSeconds
(
new
Date
(),
new
Long
(
seconds
).
intValue
());
onlineUserDto
=
new
OnlineUserDto
(
jwtUserDto
.
getUsername
(),
browser
,
ip
,
address
,
EncryptUtils
.
desEncrypt
(
token
),
new
Date
(),
exTime
,
jwtUserDto
.
getImageStr
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
OnlineUserService
.
onlineUserMap
.
put
(
onlineUserService
.
properties
.
getOnlineKey
()
+
token
,
onlineUserDto
);
// 返回 token 与 用户信息
Map
<
String
,
Object
>
authInfo
=
new
HashMap
<
String
,
Object
>(
2
)
{{
put
(
"token"
,
properties
.
getTokenStartWith
()
+
token
);
put
(
"user"
,
jwtUserDto
);
}};
if
(
loginProperties
.
isSingleLogin
())
{
//踢掉之前已经登录的token
onlineUserService
.
checkLoginOnUser
(
user
.
getUsername
(),
token
);
}
//重新登陆时清理调试模式状态
SecurityUtils
.
updateToDebugModel
(
user
.
getUsername
(),
false
);
return
ResponseEntity
.
ok
(
authInfo
);
}
@AnonymousGetMapping
(
value
=
"/code"
)
public
ResponseEntity
<
Object
>
getCode
()
{
...
...
src/main/java/com/neotel/smfcore/security/rest/UserController.java
查看文件 @
2f7c27f
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
neotel
.
smfcore
.
security
.
rest
;
import
cn.hutool.extra.qrcode.QrCodeUtil
;
import
cn.hutool.extra.qrcode.QrConfig
;
import
com.neotel.smfcore.common.bean.PageData
;
import
com.neotel.smfcore.common.bean.ResultBean
;
import
com.neotel.smfcore.common.csv.CsvReader
;
...
...
@@ -358,4 +360,26 @@ public class UserController {
return
ResultBean
.
newOkResult
(
"smfcore.exitDebugModel.ok"
,
"已退出调试模式"
,
new
String
[]{},
false
);
}
@ApiOperation
(
"生成用户授权的二维码"
)
@PostMapping
(
value
=
"/userQrcode"
)
//@AnonymousAccess
public
ResultBean
userQrcode
(
@RequestBody
Map
<
String
,
String
>
paramMap
)
{
String
id
=
paramMap
.
get
(
"id"
);
if
(
StringUtils
.
isEmpty
(
id
))
{
return
ResultBean
.
newErrorResult
(-
1
,
"smfcore.valueCanotNull"
,
"{0}不能为空"
,
new
String
[]{
"id"
});
}
User
user
=
userManager
.
get
(
id
);
//用户登录的授权code
String
loginCode
=
user
.
getLoginCode
();
if
(
StringUtils
.
isEmpty
(
loginCode
))
{
loginCode
=
id
+
"-"
+
Md5Utls
.
getMd5
(
id
,
user
.
getCreateDate
());
user
.
setLoginCode
(
loginCode
);
userManager
.
save
(
user
);
}
QrConfig
config
=
new
QrConfig
();
byte
[]
codeBytes
=
QrCodeUtil
.
generatePng
(
loginCode
,
config
);
return
ResultBean
.
newOkResult
(
codeBytes
);
}
}
src/main/java/com/neotel/smfcore/security/service/po/User.java
查看文件 @
2f7c27f
...
...
@@ -64,6 +64,8 @@ public class User extends BasePo implements Serializable {
*/
private
String
imageStr
;
private
String
loginCode
;
public
boolean
hasGroup
(
String
groupId
)
{
if
(
groupId
==
null
||
groupId
.
equals
(
""
)
||
groupId
.
equals
(
"-1"
))
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论