diff --git a/controllers/addnew.go b/controllers/addnew.go new file mode 100644 index 000000000..b7894050a --- /dev/null +++ b/controllers/addnew.go @@ -0,0 +1,30 @@ +package controllers + +import ( + "net/http" + + "github.com/vmware/harbor/dao" + "github.com/vmware/harbor/utils/log" +) + +type AddNewController struct { + BaseController +} + +func (anc *AddNewController) Get() { + sessionUserID := anc.GetSession("userId") + anc.Data["AddNew"] = false + if sessionUserID != nil { + isAdmin, err := dao.IsAdminRole(sessionUserID.(int)) + if err != nil { + log.Errorf("Error occurred in IsAdminRole: %v", err) + anc.CustomAbort(http.StatusInternalServerError, "") + } + if isAdmin && anc.AuthMode == "db_auth" { + anc.Data["AddNew"] = true + anc.Forward("Add User", "sign-up.htm") + return + } + } + anc.CustomAbort(http.StatusUnauthorized, "Status Unauthorized.") +} diff --git a/controllers/optionalmenu.go b/controllers/optionalmenu.go index 21118c7f1..ac4cc3098 100644 --- a/controllers/optionalmenu.go +++ b/controllers/optionalmenu.go @@ -18,6 +18,8 @@ func (omc *OptionalMenuController) Get() { sessionUserID := omc.GetSession("userId") var hasLoggedIn bool + var allowAddNew bool + if sessionUserID != nil { hasLoggedIn = true userID := sessionUserID.(int) @@ -31,7 +33,18 @@ func (omc *OptionalMenuController) Get() { omc.CustomAbort(http.StatusUnauthorized, "") } omc.Data["Username"] = u.Username + + isAdmin, err := dao.IsAdminRole(sessionUserID.(int)) + if err != nil { + log.Errorf("Error occurred in IsAdminRole: %v", err) + omc.CustomAbort(http.StatusInternalServerError, "") + } + + if isAdmin && omc.AuthMode == "db_auth" { + allowAddNew = true + } } + omc.Data["AddNew"] = allowAddNew omc.Data["HasLoggedIn"] = hasLoggedIn omc.TplName = "optional-menu.htm" omc.Render() diff --git a/controllers/signin.go b/controllers/signin.go index 4adfd0942..8f70acf32 100644 --- a/controllers/signin.go +++ b/controllers/signin.go @@ -32,6 +32,7 @@ func (sic *SignInController) Get() { } username = u.Username } + sic.Data["AuthMode"] = sic.AuthMode sic.Data["Username"] = username sic.Data["HasLoggedIn"] = hasLoggedIn sic.TplName = "sign-in.htm" diff --git a/controllers/signup.go b/controllers/signup.go index 97214aab1..4f2cd2b4f 100644 --- a/controllers/signup.go +++ b/controllers/signup.go @@ -1,5 +1,9 @@ package controllers +import ( + "net/http" +) + // SignUpController handles requests to /sign_up type SignUpController struct { BaseController @@ -7,5 +11,9 @@ type SignUpController struct { // Get renders sign up page func (suc *SignUpController) Get() { + if suc.AuthMode != "db_auth" { + suc.CustomAbort(http.StatusUnauthorized, "Status unauthorized.") + } + suc.Data["AddNew"] = false suc.Forward("Sign Up", "sign-up.htm") } diff --git a/static/resources/js/harbor.module.js b/static/resources/js/harbor.module.js index 2ccb547a5..18eee78d1 100644 --- a/static/resources/js/harbor.module.js +++ b/static/resources/js/harbor.module.js @@ -9,6 +9,7 @@ 'harbor.layout.header', 'harbor.layout.navigation', 'harbor.layout.sign.up', + 'harbor.layout.add.new', 'harbor.layout.account.setting', 'harbor.layout.forgot.password', 'harbor.layout.reset.password', diff --git a/static/resources/js/layout/add-new/add-new.controller.js b/static/resources/js/layout/add-new/add-new.controller.js new file mode 100644 index 000000000..4cc98e738 --- /dev/null +++ b/static/resources/js/layout/add-new/add-new.controller.js @@ -0,0 +1,15 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.layout.add.new') + .controller('AddNewController', AddNewController); + + AddNewController.$inject = []; + + function AddNewController() { + var vm = this; + } + +})(); \ No newline at end of file diff --git a/static/resources/js/layout/add-new/add-new.module.js b/static/resources/js/layout/add-new/add-new.module.js new file mode 100644 index 000000000..a130f6d53 --- /dev/null +++ b/static/resources/js/layout/add-new/add-new.module.js @@ -0,0 +1,8 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.layout.add.new', []); + +})(); \ No newline at end of file diff --git a/static/resources/js/layout/sign-up/sign-up.controller.js b/static/resources/js/layout/sign-up/sign-up.controller.js index e708d170b..b986892bf 100644 --- a/static/resources/js/layout/sign-up/sign-up.controller.js +++ b/static/resources/js/layout/sign-up/sign-up.controller.js @@ -39,7 +39,12 @@ } function confirm() { - $window.location.href = '/'; + if(location.pathname === '/add_new') { + $window.location.href = '/dashboard'; + }else{ + $window.location.href = '/'; + } + } } diff --git a/static/resources/js/services/i18n/locale_messages_en-US.js b/static/resources/js/services/i18n/locale_messages_en-US.js index 2faa498dd..4bfa98fd4 100644 --- a/static/resources/js/services/i18n/locale_messages_en-US.js +++ b/static/resources/js/services/i18n/locale_messages_en-US.js @@ -172,5 +172,8 @@ var locale_messages = { 'send': 'Send', 'successful_signed_up': 'Signed up successfully.', 'add_new_policy': 'Add New Policy', - 'edit_policy': 'Edit Policy' + 'edit_policy': 'Edit Policy', + 'add_new_title': 'Add User', + 'add_new': 'Add', + 'successful_added': 'Added new user successfully.' }; \ No newline at end of file diff --git a/static/resources/js/services/i18n/locale_messages_zh-CN.js b/static/resources/js/services/i18n/locale_messages_zh-CN.js index 1f0ee77af..d605b481a 100644 --- a/static/resources/js/services/i18n/locale_messages_zh-CN.js +++ b/static/resources/js/services/i18n/locale_messages_zh-CN.js @@ -162,7 +162,7 @@ var locale_messages = { 'successful_changed_password': '修改密码操作成功。', 'change_profile': '修改个人信息', 'successful_changed_profile': '修改个人信息操作成功。', - 'form_is_invalid': '表单内容无效', + 'form_is_invalid': '表单内容无sign_up效', 'form_is_invalid_message': '表单内容无效,请填写必填字段。', 'administrator': '管理员', 'popular_repositories': '热门镜像仓库', @@ -171,5 +171,8 @@ var locale_messages = { 'send': '发送', 'successful_signed_up': '注册成功。', 'add_new_policy': '新增策略', - 'edit_policy': '修改策略' + 'edit_policy': '修改策略', + 'add_new_title': '新增用户', + 'add_new': '新增', + 'successful_added': '新增用户成功。' }; \ No newline at end of file diff --git a/ui/router.go b/ui/router.go index c560b0d07..cdf6524c6 100644 --- a/ui/router.go +++ b/ui/router.go @@ -35,6 +35,7 @@ func initRouters() { beego.Router("/project", &controllers.ProjectController{}) beego.Router("/repository", &controllers.RepositoryController{}) beego.Router("/sign_up", &controllers.SignUpController{}) + beego.Router("/add_new", &controllers.AddNewController{}) beego.Router("/account_setting", &controllers.AccountSettingController{}) beego.Router("/admin_option", &controllers.AdminOptionController{}) beego.Router("/forgot_password", &controllers.ForgotPasswordController{}) diff --git a/views/forgot-password.htm b/views/forgot-password.htm index 8af64cab4..baa0918a8 100644 --- a/views/forgot-password.htm +++ b/views/forgot-password.htm @@ -6,7 +6,7 @@

// 'forgot_password' | tr //

-
+
diff --git a/views/optional-menu.htm b/views/optional-menu.htm index f09e21424..757449dcd 100644 --- a/views/optional-menu.htm +++ b/views/optional-menu.htm @@ -4,6 +4,9 @@ {{ .Username }}
+ {{ if eq .AuthMode "db_auth" }}
@@ -43,5 +46,6 @@
+ {{ end }} {{ end }} \ No newline at end of file diff --git a/views/sign-up.htm b/views/sign-up.htm index 6e17dc91f..ed9bf337f 100644 --- a/views/sign-up.htm +++ b/views/sign-up.htm @@ -2,8 +2,18 @@
+ {{ if eq .AddNew true }} + + {{ else }} -

// 'sign_up' | tr //

+ {{ end }} +

+ {{ if eq .AddNew true }} + // 'add_new_title' | tr // + {{ else }} + // 'sign_up' | tr // + {{ end }} +

@@ -90,7 +100,11 @@
- + {{ if eq .AddNew true }} + + {{ else }} + + {{ end }}