diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java index 26ced3d0e72..9394a327bdc 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java @@ -85,6 +85,7 @@ protected void refresh() { this.source.put(key, value); } + } } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/auth/WebSecurityConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/auth/WebSecurityConfig.java index 024bcc222c3..68d5f43f872 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/auth/WebSecurityConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/auth/WebSecurityConfig.java @@ -25,4 +25,5 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception auth.inMemoryAuthentication().withUser("user").password("").roles("USER").and() .withUser("apollo").password("").roles("USER", "ADMIN"); } + } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java index c2628837bb6..5cfd0b89c63 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java @@ -1,11 +1,11 @@ package com.ctrip.framework.apollo.common.config; import com.google.common.base.Splitter; +import com.google.common.base.Strings; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.tracer.Tracer; -import com.google.common.base.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index c34b04f8cb2..c6fc89677bf 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -29,11 +29,9 @@ public class PortalConfig extends RefreshableConfig { private static final Type ORGANIZATION = new TypeToken>() { }.getType(); - @Autowired private PortalDBPropertySource portalDBPropertySource; - @Override public List getRefreshablePropertySources() { return Collections.singletonList(portalDBPropertySource); @@ -102,7 +100,7 @@ public boolean isEmergencyPublishAllowed(Env env) { String[] emergencyPublishSupportedEnvs = getArrayProperty("emergencyPublish.supported.envs", new String[0]); - for (String supportedEnv: emergencyPublishSupportedEnvs) { + for (String supportedEnv : emergencyPublishSupportedEnvs) { if (Objects.equals(targetEnv, supportedEnv.toUpperCase().trim())) { return true; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java index c74aba11ab5..ff91f2409e6 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java @@ -56,7 +56,6 @@ public class AppController { @Autowired private RolePermissionService rolePermissionService; - @RequestMapping(value = "", method = RequestMethod.GET) public List findApps(@RequestParam(value = "appIds", required = false) String appIds) { if (StringUtils.isEmpty(appIds)) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SignInController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SignInController.java new file mode 100644 index 00000000000..6329fd077b3 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SignInController.java @@ -0,0 +1,20 @@ +package com.ctrip.framework.apollo.portal.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author lepdou 2017-08-30 + */ +@Controller +public class SignInController { + + @RequestMapping(value = "/signin", method = RequestMethod.GET) + public String login(@RequestParam(value = "error", required = false) String error, + @RequestParam(value = "logout", required = false) String logout) { + return "login.html"; + } + +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java index b62859520a6..f135bbbef20 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java @@ -1,12 +1,18 @@ 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.spi.LogoutHandler; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; -import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; import com.ctrip.framework.apollo.portal.spi.UserService; +import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService; 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; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -29,6 +35,22 @@ public class UserInfoController { @Autowired private UserService userService; + + @PreAuthorize(value = "@permissionValidator.isSuperAdmin()") + @RequestMapping(value = "/users", method = RequestMethod.POST) + public void createOrUpdateUser(@RequestBody User user) { + if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) { + throw new BadRequestException("Username and password can not be empty."); + } + + if (userService instanceof SpringSecurityUserService) { + ((SpringSecurityUserService) userService).createOrUpdate(user); + } else { + throw new UnsupportedOperationException("Create or update user operation is unsupported"); + } + + } + @RequestMapping(value = "/user", method = RequestMethod.GET) public UserInfo getCurrentUserName() { return userInfoHolder.getUser(); @@ -50,4 +72,6 @@ public List searchUsersByKeyword(@RequestParam(value = "keyword") Stri public UserInfo getUserByUserId(@PathVariable String userId) { return userService.findByUserId(userId); } + + } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java index 9c217e3df25..7edf69ef308 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java @@ -1,11 +1,20 @@ 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; private String email; + public UserInfo() { + + } + + public UserInfo(String userId) { + this.userId = userId; + } + public String getUserId() { return userId; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java new file mode 100644 index 00000000000..b274287f800 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java @@ -0,0 +1,68 @@ +package com.ctrip.framework.apollo.portal.entity.po; + +import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @author lepdou 2017-04-08 + */ +@Entity +@Table(name = "users") +public class UserPO { + + @Id + @GeneratedValue + @Column(name = "Id") + private long id; + @Column(name = "username", nullable = false) + private String username; + @Column(name = "password", nullable = false) + private String password; + @Column(name = "enabled", nullable = false) + private int enabled; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getEnabled() { + return enabled; + } + + public void setEnabled(int enabled) { + this.enabled = enabled; + } + + public UserInfo toUserInfo() { + UserInfo userInfo = new UserInfo(); + userInfo.setName(this.getUsername()); + userInfo.setUserId(this.getUsername()); + userInfo.setEmail("apollo@acme.com"); + return userInfo; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java new file mode 100644 index 00000000000..aa2adb17ad1 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java @@ -0,0 +1,17 @@ +package com.ctrip.framework.apollo.portal.repository; + +import com.ctrip.framework.apollo.portal.entity.po.UserPO; + +import org.springframework.data.repository.PagingAndSortingRepository; + +import java.util.List; + +/** + * @author lepdou 2017-04-08 + */ +public interface UserRepository extends PagingAndSortingRepository { + + List findByUsernameLike(String username); + + UserPO findByUsername(String username); +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java index 146c06988d3..73106cd8832 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java @@ -1,5 +1,8 @@ package com.ctrip.framework.apollo.portal.spi.configuration; +import com.google.common.collect.Maps; + +import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile; import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.spi.LogoutHandler; import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler; @@ -13,7 +16,10 @@ import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultSsoHeartbeatHandler; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserInfoHolder; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserService; -import com.google.common.collect.Maps; +import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserInfoHolder; +import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService; + +import org.apache.tomcat.jdbc.pool.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.embedded.FilterRegistrationBean; @@ -21,6 +27,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.core.annotation.Order; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.JdbcUserDetailsManager; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; import javax.servlet.Filter; import java.util.EventListener; @@ -170,10 +186,89 @@ public SsoHeartbeatHandler ctripSsoHeartbeatHandler() { /** - * spring.profiles.active != ctrip + * spring.profiles.active = auth */ @Configuration - @Profile({"!ctrip"}) + @Profile("auth") + static class SpringSecurityAuthAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(SsoHeartbeatHandler.class) + public SsoHeartbeatHandler defaultSsoHeartbeatHandler() { + return new DefaultSsoHeartbeatHandler(); + } + + @Bean + @ConditionalOnMissingBean(UserInfoHolder.class) + public UserInfoHolder springSecurityUserInfoHolder() { + return new SpringSecurityUserInfoHolder(); + } + + @Bean + @ConditionalOnMissingBean(LogoutHandler.class) + public LogoutHandler logoutHandler() { + return new DefaultLogoutHandler(); + } + + @Bean + public JdbcUserDetailsManager jdbcUserDetailsManager(DataSource datasource) { + JdbcUserDetailsManager userDetailsService = new JdbcUserDetailsManager(); + userDetailsService.setDataSource(datasource); + + return userDetailsService; + } + + @Bean + @ConditionalOnMissingBean(UserService.class) + public UserService springSecurityUserService() { + return new SpringSecurityUserService(); + } + + + @Order(99) + @Configuration + @Profile("auth") + @EnableWebSecurity + @EnableGlobalMethodSecurity(prePostEnabled = true) + static class SpringSecurityConfigurer extends WebSecurityConfigurerAdapter { + + public static final String USER_ROLE = "user"; + + @Autowired + private DataSource datasource; + + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + http.headers().frameOptions().sameOrigin(); + http.authorizeRequests() + .antMatchers("/openapi/*").permitAll() + .antMatchers("/*").hasAnyRole(USER_ROLE); + http.formLogin().loginPage("/signin").permitAll().failureUrl("/signin?#/error").and().httpBasic(); + http.logout().invalidateHttpSession(true).clearAuthentication(true).logoutSuccessUrl("/signin?#/logout"); + http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/signin")); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth, JdbcUserDetailsManager userDetailsService) + throws Exception { + PasswordEncoder encoder = new BCryptPasswordEncoder(); + + auth.userDetailsService(userDetailsService).passwordEncoder(encoder); + auth.jdbcAuthentication().dataSource(datasource).usersByUsernameQuery( + "select username,password, enabled from users where username=?"); + } + + } + + } + + /** + * default profile + */ + @Configuration + @ConditionalOnMissingProfile({"ctrip", "auth"}) static class DefaultAuthAutoConfiguration { @Bean @@ -184,7 +279,7 @@ public SsoHeartbeatHandler defaultSsoHeartbeatHandler() { @Bean @ConditionalOnMissingBean(UserInfoHolder.class) - public DefaultUserInfoHolder notCtripUserInfoHolder() { + public DefaultUserInfoHolder defaultUserInfoHolder() { return new DefaultUserInfoHolder(); } @@ -199,8 +294,6 @@ public DefaultLogoutHandler logoutHandler() { public UserService defaultUserService() { return new DefaultUserService(); } - } - } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java index eefa2a18786..6b609fae050 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java @@ -5,13 +5,8 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; import com.ctrip.framework.apollo.portal.spi.UserService; -import org.springframework.util.CollectionUtils; - import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** * @author Jason Song(song_s@ctrip.com) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java new file mode 100644 index 00000000000..e0ef3a3d079 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java @@ -0,0 +1,18 @@ +package com.ctrip.framework.apollo.portal.spi.springsecurity; + +import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; +import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; + +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; + +public class SpringSecurityUserInfoHolder implements UserInfoHolder { + + @Override + public UserInfo getUser() { + UserInfo userInfo = new UserInfo(); + String userId = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(); + userInfo.setUserId(userId); + return userInfo; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java new file mode 100644 index 00000000000..3065a122947 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java @@ -0,0 +1,89 @@ +package com.ctrip.framework.apollo.portal.spi.springsecurity; + +import com.google.common.collect.Lists; + +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.repository.UserRepository; +import com.ctrip.framework.apollo.portal.spi.UserService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +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.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; + +/** + * @author lepdou 2017-03-10 + */ +public class SpringSecurityUserService implements UserService { + + private PasswordEncoder encoder = new BCryptPasswordEncoder(); + private List authorities; + + @Autowired + private JdbcUserDetailsManager userDetailsManager; + @Autowired + private UserRepository userRepository; + + @PostConstruct + public void init() { + authorities = new ArrayList<>(); + authorities.add(new SimpleGrantedAuthority("ROLE_user")); + } + + public void createOrUpdate(User user) { + String username = user.getUsername(); + + User userDetails = new User(username, encoder.encode(user.getPassword()), authorities); + + if (userDetailsManager.userExists(username)) { + userDetailsManager.updateUser(userDetails); + } else { + userDetailsManager.createUser(userDetails); + } + + } + + @Override + public List searchUsers(String keyword, int offset, int limit) { + if (StringUtils.isEmpty(keyword)) { + return Collections.emptyList(); + } + + List userPOs = userRepository.findByUsernameLike("%" + keyword + "%"); + + List result = Lists.newArrayList(); + if (CollectionUtils.isEmpty(userPOs)) { + return result; + } + + result.addAll(userPOs.stream().map(UserPO::toUserInfo).collect(Collectors.toList())); + + return result; + } + + @Override + public UserInfo findByUserId(String userId) { + UserPO userPO = userRepository.findByUsername(userId); + return userPO == null ? null : userPO.toUserInfo(); + } + + @Override + public List findByUserIds(List userIds) { + return null; + } + + +} diff --git a/apollo-portal/src/main/resources/static/index.html b/apollo-portal/src/main/resources/static/index.html index a0dbddbf667..fe6e37a40ea 100644 --- a/apollo-portal/src/main/resources/static/index.html +++ b/apollo-portal/src/main/resources/static/index.html @@ -30,7 +30,8 @@
我的项目
创建项目
-
+

diff --git a/apollo-portal/src/main/resources/static/login.html b/apollo-portal/src/main/resources/static/login.html new file mode 100644 index 00000000000..f486ed38fd1 --- /dev/null +++ b/apollo-portal/src/main/resources/static/login.html @@ -0,0 +1,336 @@ + + + + + Apollo配置中心 + + + + + + + +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + diff --git a/apollo-portal/src/main/resources/static/scripts/app.js b/apollo-portal/src/main/resources/static/scripts/app.js index db7256c3d9d..04e3e863d14 100644 --- a/apollo-portal/src/main/resources/static/scripts/app.js +++ b/apollo-portal/src/main/resources/static/scripts/app.js @@ -30,7 +30,10 @@ var cluster_module = angular.module('cluster', ['app.service', 'apollo.directive var release_history_module = angular.module('release_history', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); //open manage var open_manage_module = angular.module('open_manage', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); - +//user +var user_module = angular.module('user', ['apollo.directive', 'toastr', 'app.service', 'app.util', 'angular-loading-bar', 'valdr']); +//login +var login_module = angular.module('login', ['toastr', 'app.util']); diff --git a/apollo-portal/src/main/resources/static/scripts/controller/LoginController.js b/apollo-portal/src/main/resources/static/scripts/controller/LoginController.js new file mode 100644 index 00000000000..549689c0d23 --- /dev/null +++ b/apollo-portal/src/main/resources/static/scripts/controller/LoginController.js @@ -0,0 +1,16 @@ +login_module.controller('LoginController', + ['$scope', '$window', '$location', 'toastr', 'AppUtil', + LoginController]); + +function LoginController($scope, $window, $location, toastr, AppUtil) { + if ($location.$$url) { + var params = AppUtil.parseParams($location.$$url); + if (params.error) { + $scope.info = "用户名或密码错误"; + } + if (params.logout) { + $scope.info = "登出成功"; + } + } + +} diff --git a/apollo-portal/src/main/resources/static/scripts/controller/UserController.js b/apollo-portal/src/main/resources/static/scripts/controller/UserController.js new file mode 100644 index 00000000000..0b572015413 --- /dev/null +++ b/apollo-portal/src/main/resources/static/scripts/controller/UserController.js @@ -0,0 +1,17 @@ +user_module.controller('UserController', + ['$scope', '$window', 'toastr', 'AppUtil', 'UserService', + UserController]); + +function UserController($scope, $window, toastr, AppUtil, UserService) { + + $scope.user = {}; + + $scope.createOrUpdateUser = function () { + UserService.createOrUpdateUser($scope.user).then(function (result) { + toastr.success("创建用户成功"); + }, function (result) { + AppUtil.showErrorMsg(result, "创建用户失败"); + }) + + } +} diff --git a/apollo-portal/src/main/resources/static/scripts/services/UserService.js b/apollo-portal/src/main/resources/static/scripts/services/UserService.js index dce051000b4..bf9f53926e1 100644 --- a/apollo-portal/src/main/resources/static/scripts/services/UserService.js +++ b/apollo-portal/src/main/resources/static/scripts/services/UserService.js @@ -7,6 +7,10 @@ appService.service('UserService', ['$resource', '$q', function ($resource, $q) { find_users: { method: 'GET', url: '/users' + }, + create_or_update_user: { + method: 'POST', + url: '/users' } }); return { @@ -36,6 +40,17 @@ appService.service('UserService', ['$resource', '$q', function ($resource, $q) { d.reject(result); }); return d.promise; + }, + createOrUpdateUser: function (user) { + var d = $q.defer(); + user_resource.create_or_update_user({}, user, + function (result) { + d.resolve(result); + }, + function (result) { + d.reject(result); + }); + return d.promise; } } }]); diff --git a/apollo-portal/src/main/resources/static/user-manage.html b/apollo-portal/src/main/resources/static/user-manage.html new file mode 100644 index 00000000000..199fe4e8b3f --- /dev/null +++ b/apollo-portal/src/main/resources/static/user-manage.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + + 用户管理 + + + + + +
+ +
+
+
+
+ 用户管理 +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+
+ +
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apollo-portal/src/main/resources/static/views/common/nav.html b/apollo-portal/src/main/resources/static/views/common/nav.html index 3f65a854421..f45c25986ec 100644 --- a/apollo-portal/src/main/resources/static/views/common/nav.html +++ b/apollo-portal/src/main/resources/static/views/common/nav.html @@ -25,16 +25,15 @@ 帮助 - +