提交 7c148cc7 编写于 作者: L lepdou

support user email field

上级 1e165540
......@@ -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 UserPO user) {
if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) {
throw new BadRequestException("Username and password can not be empty.");
}
......
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;
......
......@@ -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.getUsername() + "@acme.com");
userInfo.setEmail(this.getEmail());
return userInfo;
}
}
......@@ -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
......
......@@ -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">
......
......@@ -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='用户表';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册