Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-ui
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
qinchao
7 years ago
Commit
954efdc99b7836a4017a0ebc587e885a454d9bed
1 parent
0fe0d9a6
用户检测,没有用户的时候自动新增
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
33 deletions
monitor-ui-ctrl/src/main/java/com/ui/ctrl/ManagerCtrl.java
monitor-ui-ctrl/src/main/java/com/ui/ctrl/UserCtrl.java
monitor-ui-ctrl/src/main/java/com/ui/ctrl/UserSaveComponent.java
monitor-ui-ctrl/src/main/java/com/ui/ctrl/ManagerCtrl.java
View file @
954efdc
...
...
@@ -37,6 +37,9 @@ public class ManagerCtrl {
@Autowired
UserAuthLocal
userAuthLocal
;
@Autowired
UserSaveComponent
userSaveComponent
;
@RequestMapping
(
"/toUser"
)
public
ModelAndView
toAddUser
()
{
return
new
ModelAndView
(
"manager/user"
);
...
...
@@ -94,36 +97,7 @@ public class ManagerCtrl {
@RequestMapping
(
"/saveUser"
)
@ResponseBody
public
BaseResponse
saveUser
(
@RequestBody
User
user
,
HttpSession
session
)
{
BaseResponse
baseResponse
=
null
;
if
(
StringUtils
.
isNotBlank
(
user
.
getModules
())
&&
StringUtils
.
endsWith
(
user
.
getModules
(),
","
))
{
user
.
setModules
(
user
.
getModules
().
substring
(
0
,
user
.
getModules
().
length
()
-
1
));
}
if
(
StringUtils
.
isNotBlank
(
user
.
getModuleGroups
())
&&
StringUtils
.
endsWith
(
user
.
getModuleGroups
(),
","
))
{
user
.
setModuleGroups
(
user
.
getModuleGroups
().
substring
(
0
,
user
.
getModuleGroups
().
length
()
-
1
));
}
if
(
StringUtils
.
isBlank
(
user
.
getEmail
())||
StringUtils
.
isBlank
(
user
.
getMobile
())){
return
new
BaseResponse
(
201
,
"邮箱、手机号不能为空"
);
}
if
(
StringUtils
.
isBlank
(
user
.
getLadpName
())){
user
.
setLadpName
(
user
.
getEmail
().
substring
(
0
,
user
.
getEmail
().
indexOf
(
"@"
)));
}
if
(
user
.
getId
()
<
1
)
{
//add
if
(
userAuthLocal
.
getUserByname
(
user
.
getName
())
!=
null
)
{
return
new
BaseResponse
(
201
,
"用户已经存在"
);
}
user
.
setPwd
(
RandomStringUtils
.
random
(
8
,
true
,
true
));
baseResponse
=
httpRestClient
.
defaultPost
(
HttpUriContants
.
USER_INSERT
,
user
,
BaseResponse
.
class
);
}
else
{
User
u
=
(
User
)
session
.
getAttribute
(
"user"
);
String
username
=
u
.
getName
();
if
(
"admin"
.
equals
(
user
.
getName
())
&&
!
"admin"
.
equals
(
username
))
{
return
new
BaseResponse
(
201
,
"此用户无法修改"
);
}
baseResponse
=
httpRestClient
.
defaultPost
(
HttpUriContants
.
USER_UPDATE
,
user
,
BaseResponse
.
class
);
}
userAuthLocal
.
flushUser
(
user
.
getName
());
return
baseResponse
;
return
userSaveComponent
.
saveUser
(
user
,
session
);
}
@RequestMapping
(
"/getUsers"
)
...
...
monitor-ui-ctrl/src/main/java/com/ui/ctrl/UserCtrl.java
View file @
954efdc
...
...
@@ -38,11 +38,15 @@ public class UserCtrl {
private
HttpRestClient
httpRestClient
;
@Autowired
UserAuthLocal
userAuthLocal
;
private
UserSaveComponent
userSaveComponent
;
@Autowired
private
UserAuthLocal
userAuthLocal
;
@Autowired
private
LdapAuthUtil
ldapAuthenticate
;
@RequestMapping
(
"/toLogin"
)
public
ModelAndView
toLogin
(
String
loginTargetUrl
,
Model
model
)
{
if
(
StringUtils
.
isNotBlank
(
loginTargetUrl
)){
...
...
@@ -91,8 +95,25 @@ public class UserCtrl {
if
(
u
==
null
)
{
//创建默认的用户
model
.
addAttribute
(
"message"
,
"用户名不存在,如有需要请联系管理员添加用户"
);
return
new
ModelAndView
(
"user/login"
);
User
createDefaultUser
=
new
User
();
createDefaultUser
.
setId
(
0
);
createDefaultUser
.
setEmail
(
user
.
getName
()+
"@yoho.cn"
);
createDefaultUser
.
setName
(
user
.
getName
());
createDefaultUser
.
setCname
(
user
.
getName
());
createDefaultUser
.
setLadpName
(
user
.
getName
());
createDefaultUser
.
setRole
(
"develop"
);
createDefaultUser
.
setModules
(
"workSystem,searchCompare,sqlOperate,redisOperate"
);
createDefaultUser
.
setAuthGroup
(
"1,2,"
);
createDefaultUser
.
setMobile
(
"00000000000"
);
userSaveComponent
.
saveUser
(
createDefaultUser
,
session
);
//保存之后再查一次
u
=
userAuthLocal
.
getUserByLdapName
(
user
.
getName
());
if
(
u
==
null
){
model
.
addAttribute
(
"message"
,
"用户名不存在,如有需要请联系管理员添加用户"
);
return
new
ModelAndView
(
"user/login"
);
}
}
...
...
monitor-ui-ctrl/src/main/java/com/ui/ctrl/UserSaveComponent.java
0 → 100644
View file @
954efdc
package
com
.
ui
.
ctrl
;
import
com.ui.User.UserAuthLocal
;
import
com.ui.contants.HttpUriContants
;
import
com.ui.http.HttpRestClient
;
import
com.ui.model.BaseResponse
;
import
com.ui.model.req.User
;
import
com.ui.test.TestCommonAlarmData
;
import
com.ui.test.TestCommonData
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpSession
;
/**
* 测试转用
*/
@Component
public
class
UserSaveComponent
{
@Autowired
HttpRestClient
httpRestClient
;
@Autowired
UserAuthLocal
userAuthLocal
;
public
BaseResponse
saveUser
(
User
user
,
HttpSession
session
)
{
BaseResponse
baseResponse
=
null
;
if
(
StringUtils
.
isNotBlank
(
user
.
getModules
())
&&
StringUtils
.
endsWith
(
user
.
getModules
(),
","
))
{
user
.
setModules
(
user
.
getModules
().
substring
(
0
,
user
.
getModules
().
length
()
-
1
));
}
if
(
StringUtils
.
isNotBlank
(
user
.
getModuleGroups
())
&&
StringUtils
.
endsWith
(
user
.
getModuleGroups
(),
","
))
{
user
.
setModuleGroups
(
user
.
getModuleGroups
().
substring
(
0
,
user
.
getModuleGroups
().
length
()
-
1
));
}
if
(
StringUtils
.
isBlank
(
user
.
getEmail
())||
StringUtils
.
isBlank
(
user
.
getMobile
())){
return
new
BaseResponse
(
201
,
"邮箱、手机号不能为空"
);
}
if
(
StringUtils
.
isBlank
(
user
.
getLadpName
())){
user
.
setLadpName
(
user
.
getEmail
().
substring
(
0
,
user
.
getEmail
().
indexOf
(
"@"
)));
}
if
(
user
.
getId
()
<
1
)
{
//add
if
(
userAuthLocal
.
getUserByname
(
user
.
getName
())
!=
null
)
{
return
new
BaseResponse
(
201
,
"用户已经存在"
);
}
user
.
setPwd
(
RandomStringUtils
.
random
(
8
,
true
,
true
));
baseResponse
=
httpRestClient
.
defaultPost
(
HttpUriContants
.
USER_INSERT
,
user
,
BaseResponse
.
class
);
}
else
{
User
u
=
(
User
)
session
.
getAttribute
(
"user"
);
String
username
=
u
.
getName
();
if
(
"admin"
.
equals
(
user
.
getName
())
&&
!
"admin"
.
equals
(
username
))
{
return
new
BaseResponse
(
201
,
"此用户无法修改"
);
}
baseResponse
=
httpRestClient
.
defaultPost
(
HttpUriContants
.
USER_UPDATE
,
user
,
BaseResponse
.
class
);
}
userAuthLocal
.
flushUser
(
user
.
getName
());
return
baseResponse
;
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment