Commit 98d4693b by Jason Song Committed by GitHub

Merge pull request #746 from lepdou/email

support user email field
parents 1e165540 7c148cc7
...@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.controller; ...@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; 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.LogoutHandler;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
...@@ -10,7 +11,6 @@ import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserSe ...@@ -10,7 +11,6 @@ import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserSe
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; 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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -38,7 +38,7 @@ public class UserInfoController { ...@@ -38,7 +38,7 @@ public class UserInfoController {
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@RequestMapping(value = "/users", method = RequestMethod.POST) @RequestMapping(value = "/users", method = RequestMethod.POST)
public void createOrUpdateUser(@RequestBody User user) { public void createOrUpdateUser(@RequestBody UserPO user) {
if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) { if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) {
throw new BadRequestException("Username and password can not be empty."); throw new BadRequestException("Username and password can not be empty.");
} }
......
package com.ctrip.framework.apollo.portal.entity.bo; package com.ctrip.framework.apollo.portal.entity.bo;
public class UserInfo { public class UserInfo {
public static final UserInfo DEFAULT_USER = new UserInfo("apollo");
private String userId; private String userId;
private String name; private String name;
......
...@@ -23,6 +23,8 @@ public class UserPO { ...@@ -23,6 +23,8 @@ public class UserPO {
private String username; private String username;
@Column(name = "Password", nullable = false) @Column(name = "Password", nullable = false)
private String password; private String password;
@Column(name = "Email", nullable = false)
private String email;
@Column(name = "Enabled", nullable = false) @Column(name = "Enabled", nullable = false)
private int enabled; private int enabled;
...@@ -42,6 +44,14 @@ public class UserPO { ...@@ -42,6 +44,14 @@ public class UserPO {
this.username = username; this.username = username;
} }
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() { public String getPassword() {
return password; return password;
} }
...@@ -62,7 +72,7 @@ public class UserPO { ...@@ -62,7 +72,7 @@ public class UserPO {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setName(this.getUsername()); userInfo.setName(this.getUsername());
userInfo.setUserId(this.getUsername()); userInfo.setUserId(this.getUsername());
userInfo.setEmail(this.getUsername() + "@acme.com"); userInfo.setEmail(this.getEmail());
return userInfo; return userInfo;
} }
} }
...@@ -15,6 +15,7 @@ import org.springframework.security.core.userdetails.User; ...@@ -15,6 +15,7 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -42,7 +43,8 @@ public class SpringSecurityUserService implements UserService { ...@@ -42,7 +43,8 @@ public class SpringSecurityUserService implements UserService {
authorities.add(new SimpleGrantedAuthority("ROLE_user")); authorities.add(new SimpleGrantedAuthority("ROLE_user"));
} }
public void createOrUpdate(User user) { @Transactional
public void createOrUpdate(UserPO user) {
String username = user.getUsername(); String username = user.getUsername();
User userDetails = new User(username, encoder.encode(user.getPassword()), authorities); User userDetails = new User(username, encoder.encode(user.getPassword()), authorities);
...@@ -53,6 +55,10 @@ public class SpringSecurityUserService implements UserService { ...@@ -53,6 +55,10 @@ public class SpringSecurityUserService implements UserService {
userDetailsManager.createUser(userDetails); userDetailsManager.createUser(userDetails);
} }
UserPO managedUser = userRepository.findByUsername(username);
managedUser.setEmail(user.getEmail());
userRepository.save(managedUser);
} }
@Override @Override
......
...@@ -44,6 +44,14 @@ ...@@ -44,6 +44,14 @@
<input type="text" class="form-control" name="password" ng-model="user.password"> <input type="text" class="form-control" name="password" ng-model="user.password">
</div> </div>
</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="form-group">
<div class="col-sm-offset-2 col-sm-9"> <div class="col-sm-offset-2 col-sm-9">
......
...@@ -284,6 +284,7 @@ CREATE TABLE `Users` ( ...@@ -284,6 +284,7 @@ CREATE TABLE `Users` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id',
`Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户名', `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户名',
`Password` 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 '是否有效', `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效',
PRIMARY KEY (`Id`) PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment