Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
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
openSource
apollo
Commits
7c148cc7
Commit
7c148cc7
authored
Sep 08, 2017
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support user email field
parent
1e165540
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
5 deletions
+29
-5
UserInfoController.java
...ramework/apollo/portal/controller/UserInfoController.java
+2
-2
UserInfo.java
...com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java
+0
-1
UserPO.java
...a/com/ctrip/framework/apollo/portal/entity/po/UserPO.java
+11
-1
SpringSecurityUserService.java
.../portal/spi/springsecurity/SpringSecurityUserService.java
+7
-1
user-manage.html
apollo-portal/src/main/resources/static/user-manage.html
+8
-0
apolloportaldb.sql
scripts/sql/apolloportaldb.sql
+1
-0
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java
View file @
7c148cc7
...
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.controller;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.UserPO
;
import
com.ctrip.framework.apollo.portal.spi.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
...
...
@@ -10,7 +11,6 @@ import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserSe
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -38,7 +38,7 @@ public class UserInfoController {
@PreAuthorize
(
value
=
"@permissionValidator.isSuperAdmin()"
)
@RequestMapping
(
value
=
"/users"
,
method
=
RequestMethod
.
POST
)
public
void
createOrUpdateUser
(
@RequestBody
User
user
)
{
public
void
createOrUpdateUser
(
@RequestBody
User
PO
user
)
{
if
(
StringUtils
.
isContainEmpty
(
user
.
getUsername
(),
user
.
getPassword
()))
{
throw
new
BadRequestException
(
"Username and password can not be empty."
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java
View file @
7c148cc7
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
entity
.
bo
;
public
class
UserInfo
{
public
static
final
UserInfo
DEFAULT_USER
=
new
UserInfo
(
"apollo"
);
private
String
userId
;
private
String
name
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java
View file @
7c148cc7
...
...
@@ -23,6 +23,8 @@ public class UserPO {
private
String
username
;
@Column
(
name
=
"Password"
,
nullable
=
false
)
private
String
password
;
@Column
(
name
=
"Email"
,
nullable
=
false
)
private
String
email
;
@Column
(
name
=
"Enabled"
,
nullable
=
false
)
private
int
enabled
;
...
...
@@ -42,6 +44,14 @@ public class UserPO {
this
.
username
=
username
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getPassword
()
{
return
password
;
}
...
...
@@ -62,7 +72,7 @@ public class UserPO {
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setName
(
this
.
getUsername
());
userInfo
.
setUserId
(
this
.
getUsername
());
userInfo
.
setEmail
(
this
.
get
Username
()
+
"@acme.com"
);
userInfo
.
setEmail
(
this
.
get
Email
()
);
return
userInfo
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java
View file @
7c148cc7
...
...
@@ -15,6 +15,7 @@ import org.springframework.security.core.userdetails.User;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.provisioning.JdbcUserDetailsManager
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
...
...
@@ -42,7 +43,8 @@ public class SpringSecurityUserService implements UserService {
authorities
.
add
(
new
SimpleGrantedAuthority
(
"ROLE_user"
));
}
public
void
createOrUpdate
(
User
user
)
{
@Transactional
public
void
createOrUpdate
(
UserPO
user
)
{
String
username
=
user
.
getUsername
();
User
userDetails
=
new
User
(
username
,
encoder
.
encode
(
user
.
getPassword
()),
authorities
);
...
...
@@ -53,6 +55,10 @@ public class SpringSecurityUserService implements UserService {
userDetailsManager
.
createUser
(
userDetails
);
}
UserPO
managedUser
=
userRepository
.
findByUsername
(
username
);
managedUser
.
setEmail
(
user
.
getEmail
());
userRepository
.
save
(
managedUser
);
}
@Override
...
...
apollo-portal/src/main/resources/static/user-manage.html
View file @
7c148cc7
...
...
@@ -44,6 +44,14 @@
<input
type=
"text"
class=
"form-control"
name=
"password"
ng-model=
"user.password"
>
</div>
</div>
<div
class=
"form-group"
valdr-form-group
>
<label
class=
"col-sm-2 control-label"
>
<apollorequiredfield></apollorequiredfield>
邮箱
</label>
<div
class=
"col-sm-4"
>
<input
type=
"text"
class=
"form-control"
name=
"password"
ng-model=
"user.email"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-9"
>
...
...
scripts/sql/apolloportaldb.sql
View file @
7c148cc7
...
...
@@ -284,6 +284,7 @@ CREATE TABLE `Users` (
`Id`
int
(
10
)
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'自增Id'
,
`Username`
varchar
(
64
)
NOT
NULL
DEFAULT
'default'
COMMENT
'用户名'
,
`Password`
varchar
(
64
)
NOT
NULL
DEFAULT
'default'
COMMENT
'密码'
,
`Email`
varchar
(
64
)
NOT
NULL
DEFAULT
'default'
COMMENT
'邮箱地址'
,
`Enabled`
tinyint
(
4
)
DEFAULT
NULL
COMMENT
'是否有效'
,
PRIMARY
KEY
(
`Id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COMMENT
=
'用户表'
;
...
...
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