Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 7f1a115d
由
zshaohui
编写于
2024-12-24 13:12:07 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.登录功能提交
1 个父辈
612eb27a
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
179 行增加
和
8 行删除
src/main/java/com/neotel/smfcore/common/init/DataInitManager.java
src/main/java/com/neotel/smfcore/common/utils/UserCodeUtil.java
src/main/java/com/neotel/smfcore/custom/toyota1541/controller/ToyotaLoginController.java
src/main/java/com/neotel/smfcore/security/rest/UserController.java
src/main/java/com/neotel/smfcore/security/service/po/User.java
src/main/resources/config/application.yml
src/main/resources/messages.properties
src/main/resources/messages_en_US.properties
src/main/resources/messages_ja_JP.properties
src/main/resources/messages_zh_CN.properties
src/main/resources/messages_zh_TW.properties
src/main/java/com/neotel/smfcore/common/init/DataInitManager.java
查看文件 @
7f1a115
...
@@ -89,7 +89,7 @@ public class DataInitManager {
...
@@ -89,7 +89,7 @@ public class DataInitManager {
operator
=
roleManager
.
save
(
operator
);
operator
=
roleManager
.
save
(
operator
);
log
.
info
(
"创建默认角色:"
+
operator
.
toString
());
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
);
admin
=
userManager
.
save
(
admin
);
log
.
info
(
"创建默认用户:"
+
admin
.
toString
());
log
.
info
(
"创建默认用户:"
+
admin
.
toString
());
...
...
src/main/java/com/neotel/smfcore/common/utils/UserCodeUtil.java
查看文件 @
7f1a115
...
@@ -107,7 +107,7 @@ public class UserCodeUtil {
...
@@ -107,7 +107,7 @@ public class UserCodeUtil {
String
langu
=
""
;
String
langu
=
""
;
String
roleId
=
""
;
String
roleId
=
""
;
User
user
=
new
User
(
username
,
email
,
langu
,
roleId
,
""
,
true
User
user
=
new
User
(
username
,
email
,
langu
,
roleId
,
""
,
true
,
false
,
new
Date
(),
new
HashSet
<>(),
""
);
,
false
,
new
Date
(),
new
HashSet
<>(),
""
,
""
);
user
.
setId
(
id
);
user
.
setId
(
id
);
user
.
setCreateDate
(
createData
);
user
.
setCreateDate
(
createData
);
list
.
add
(
user
);
list
.
add
(
user
);
...
...
src/main/java/com/neotel/smfcore/custom/toyota1541/controller/ToyotaLoginController.java
0 → 100644
查看文件 @
7f1a115
package
com
.
neotel
.
smfcore
.
custom
.
toyota1541
.
controller
;
import
com.neotel.smfcore.common.bean.ResultBean
;
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.TokenProvider
;
import
com.neotel.smfcore.security.annotation.AnonymousPostMapping
;
import
com.neotel.smfcore.security.bean.LoginProperties
;
import
com.neotel.smfcore.security.bean.RsaProperties
;
import
com.neotel.smfcore.security.bean.SecurityProperties
;
import
com.neotel.smfcore.security.rest.bean.dto.AuthUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto
;
import
com.neotel.smfcore.security.service.OnlineUserService
;
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
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
@Api
(
tags
=
"登录"
)
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/toyotaLogin"
)
public
class
ToyotaLoginController
{
private
final
SecurityProperties
properties
;
@Autowired
private
OnlineUserService
onlineUserService
;
@Autowired
private
TokenProvider
tokenProvider
;
private
final
AuthenticationManagerBuilder
authenticationManagerBuilder
;
@Resource
private
LoginProperties
loginProperties
;
@Autowired
private
IUserManager
userManager
;
@Autowired
private
UserDetailsService
userDetailsService
;
@ApiOperation
(
"登录授权"
)
@AnonymousPostMapping
(
value
=
"/login"
)
public
ResponseEntity
<
Object
>
login
(
@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
(
StringUtils
.
isEmpty
(
loginCode
)){
loginCode
=
id
+
"-"
+
Md5Utls
.
getMd5
(
id
,
user
.
getCreateDate
());
}
if
(
StringUtils
.
isEmpty
(
user
.
getLoginCode
())){
user
.
setLoginCode
(
loginCode
);
userManager
.
save
(
user
);
}
if
(!
loginCode
.
equals
(
code
)){
throw
new
ValidateException
(
"smfcore.login.codeError"
,
"登录码[{0}]错误"
,
new
String
[]{
code
});
}
/* UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(user.getUsername(), password);
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);*/
// 生成令牌与第三方系统获取令牌方式
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
);
}
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
);
}
}
src/main/java/com/neotel/smfcore/security/rest/UserController.java
查看文件 @
7f1a115
...
@@ -15,11 +15,16 @@
...
@@ -15,11 +15,16 @@
*/
*/
package
com
.
neotel
.
smfcore
.
security
.
rest
;
package
com
.
neotel
.
smfcore
.
security
.
rest
;
import
cn.hutool.extra.qrcode.QrCodeUtil
;
import
cn.hutool.extra.qrcode.QrConfig
;
import
com.google.zxing.multi.qrcode.QRCodeMultiReader
;
import
com.neotel.smfcore.common.bean.PageData
;
import
com.neotel.smfcore.common.bean.PageData
;
import
com.neotel.smfcore.common.bean.ResultBean
;
import
com.neotel.smfcore.common.bean.ResultBean
;
import
com.neotel.smfcore.common.csv.CsvReader
;
import
com.neotel.smfcore.common.csv.CsvReader
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.utils.*
;
import
com.neotel.smfcore.common.utils.*
;
import
com.neotel.smfcore.core.barcode.utils.QrcodeUtils
;
import
com.neotel.smfcore.security.annotation.AnonymousAccess
;
import
com.neotel.smfcore.security.bean.FileProperties
;
import
com.neotel.smfcore.security.bean.FileProperties
;
import
com.neotel.smfcore.security.bean.RsaProperties
;
import
com.neotel.smfcore.security.bean.RsaProperties
;
import
com.neotel.smfcore.security.rest.bean.dto.UserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.UserDto
;
...
@@ -69,6 +74,9 @@ public class UserController {
...
@@ -69,6 +74,9 @@ public class UserController {
@Autowired
@Autowired
private
final
FileProperties
properties
;
private
final
FileProperties
properties
;
@Autowired
private
QrcodeUtils
qrcodeUtils
;
@ApiOperation
(
"导出用户数据"
)
@ApiOperation
(
"导出用户数据"
)
@GetMapping
(
value
=
"/download"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('user:list')"
)
@PreAuthorize
(
"@el.check('user:list')"
)
...
@@ -261,6 +269,31 @@ public class UserController {
...
@@ -261,6 +269,31 @@ public class UserController {
return
ResultBean
.
newOkResult
(
resultMsg
);
return
ResultBean
.
newOkResult
(
resultMsg
);
}
}
@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
());
}
if
(
StringUtils
.
isEmpty
(
user
.
getLoginCode
()))
{
user
.
setLoginCode
(
loginCode
);
userManager
.
save
(
user
);
}
QrConfig
config
=
new
QrConfig
();
byte
[]
codeBytes
=
QrCodeUtil
.
generatePng
(
loginCode
,
config
);
return
ResultBean
.
newOkResult
(
codeBytes
);
}
protected
String
handleUserUpload
(
String
fileURL
)
throws
Exception
protected
String
handleUserUpload
(
String
fileURL
)
throws
Exception
{
{
...
...
src/main/java/com/neotel/smfcore/security/service/po/User.java
查看文件 @
7f1a115
...
@@ -58,6 +58,8 @@ public class User extends BasePo implements Serializable {
...
@@ -58,6 +58,8 @@ public class User extends BasePo implements Serializable {
private
String
checkCode
;
private
String
checkCode
;
private
String
loginCode
;
public
boolean
hasGroup
(
String
groupId
)
{
public
boolean
hasGroup
(
String
groupId
)
{
if
(
groupId
==
null
||
groupId
.
equals
(
""
)
||
groupId
.
equals
(
"-1"
))
{
if
(
groupId
==
null
||
groupId
.
equals
(
""
)
||
groupId
.
equals
(
"-1"
))
{
...
...
src/main/resources/config/application.yml
查看文件 @
7f1a115
...
@@ -2,7 +2,7 @@ server:
...
@@ -2,7 +2,7 @@ server:
port
:
8800
port
:
8800
api
:
api
:
name
:
name
:
1541
inCheckUrl
:
inCheckUrl
:
outNotifyUrl
:
outNotifyUrl
:
inNotifyUrl
:
inNotifyUrl
:
...
...
src/main/resources/messages.properties
查看文件 @
7f1a115
...
@@ -401,4 +401,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
...
@@ -401,4 +401,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
smfcore.storagePos.yes=
\u
662F
smfcore.storagePos.yes=
\u
662F
smfcore.storagePos.no
=
\u5426
smfcore.storagePos.no
=
\u5426
smfcore.dashBoard
=
\u
4EEA
\u8868\u
76D8
smfcore.dashBoard
=
\u
4EEA
\u8868\u
76D8
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
\ No newline at end of file
\ No newline at end of file
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
smfcore.login.codeError
=
\u
767B
\u
5F55
\u7801
[{0}]
\u9519\u
8BEF
\ No newline at end of file
\ No newline at end of file
src/main/resources/messages_en_US.properties
查看文件 @
7f1a115
...
@@ -392,4 +392,5 @@ smfcore.storagePos.available=Available
...
@@ -392,4 +392,5 @@ smfcore.storagePos.available=Available
smfcore.storagePos.yes
=
Yes
smfcore.storagePos.yes
=
Yes
smfcore.storagePos.no
=
No
smfcore.storagePos.no
=
No
smfcore.dashBoard
=
Dashboard
smfcore.dashBoard
=
Dashboard
smfcore.spHumiture
=
Temperature & Humidity
\ No newline at end of file
\ No newline at end of file
smfcore.spHumiture
=
Temperature & Humidity
smfcore.login.codeError
=
Login code [{0}] error
\ No newline at end of file
\ No newline at end of file
src/main/resources/messages_ja_JP.properties
查看文件 @
7f1a115
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u5229\u7528\u53EF\u5426
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u5229\u7528\u53EF\u5426
smfcore.storagePos.yes=
\u
662F
smfcore.storagePos.yes=
\u
662F
smfcore.storagePos.no
=
\u5426
smfcore.storagePos.no
=
\u5426
smfcore.dashBoard
=
\u
30C0
\u
30C3
\u
30B7
\u
30E5
\u
30DC
\u
30FC
\u
30C9
smfcore.dashBoard
=
\u
30C0
\u
30C3
\u
30B7
\u
30E5
\u
30DC
\u
30FC
\u
30C9
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
\ No newline at end of file
\ No newline at end of file
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
smfcore.login.codeError
=
\u
30ED
\u
30B0
\u
30A4
\u
30F3
\u
30B3
\u
30FC
\u
30C9[{0}]
\u
30A8
\u
30E9
\u
30FC
\ No newline at end of file
\ No newline at end of file
src/main/resources/messages_zh_CN.properties
查看文件 @
7f1a115
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
smfcore.storagePos.yes
=
\u
662F
smfcore.storagePos.yes
=
\u
662F
smfcore.storagePos.no
=
\u5426
smfcore.storagePos.no
=
\u5426
smfcore.dashBoard=
\u
4EEA
\u8868\u
76D8
smfcore.dashBoard=
\u
4EEA
\u8868\u
76D8
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
\ No newline at end of file
\ No newline at end of file
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
smfcore.login.codeError
=
\u
767B
\u
5F55
\u7801
[{0}]
\u9519\u
8BEF
\ No newline at end of file
\ No newline at end of file
src/main/resources/messages_zh_TW.properties
查看文件 @
7f1a115
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
...
@@ -388,4 +388,5 @@ smfcore.storagePos.available=\u662F\u5426\u53EF\u7528
smfcore.storagePos.yes
=
\u
662F
smfcore.storagePos.yes
=
\u
662F
smfcore.storagePos.no
=
\u5426
smfcore.storagePos.no
=
\u5426
smfcore.dashBoard=SP
\u5100\u9336\u
76E4
smfcore.dashBoard=SP
\u5100\u9336\u
76E4
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
\ No newline at end of file
\ No newline at end of file
smfcore.spHumiture
=
\u
6E29
\u
6E7F
\u
5EA6
smfcore.login.codeError
=
\u
767B
\u9304\u
78BC[{0}]
\u
932F
\u
8AA4
\ No newline at end of file
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论