mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
updates for adding new user and auth_mode check feature of UI.
This commit is contained in:
parent
82de5b3bf4
commit
5e538fa9e5
30
controllers/addnew.go
Normal file
30
controllers/addnew.go
Normal file
@ -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.")
|
||||
}
|
@ -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()
|
||||
|
@ -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"
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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',
|
||||
|
15
static/resources/js/layout/add-new/add-new.controller.js
Normal file
15
static/resources/js/layout/add-new/add-new.controller.js
Normal file
@ -0,0 +1,15 @@
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('harbor.layout.add.new')
|
||||
.controller('AddNewController', AddNewController);
|
||||
|
||||
AddNewController.$inject = [];
|
||||
|
||||
function AddNewController() {
|
||||
var vm = this;
|
||||
}
|
||||
|
||||
})();
|
8
static/resources/js/layout/add-new/add-new.module.js
Normal file
8
static/resources/js/layout/add-new/add-new.module.js
Normal file
@ -0,0 +1,8 @@
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('harbor.layout.add.new', []);
|
||||
|
||||
})();
|
@ -39,7 +39,12 @@
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
$window.location.href = '/';
|
||||
if(location.pathname === '/add_new') {
|
||||
$window.location.href = '/dashboard';
|
||||
}else{
|
||||
$window.location.href = '/';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.'
|
||||
};
|
@ -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': '新增用户成功。'
|
||||
};
|
@ -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{})
|
||||
|
@ -6,7 +6,7 @@
|
||||
<h1 class="col-md-12 col-md-offset-2 main-title title-color">// 'forgot_password' | tr //</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-md-offset-2 main-content">
|
||||
<form name="form" class="form-horizontal css-form">
|
||||
<form name="form" class="form-horizontal css-form" novalidate>
|
||||
<div class="form-group">
|
||||
<label for="email" class="col-sm-3 control-label">// 'email' | tr //:</label>
|
||||
<div class="col-sm-7">
|
||||
|
@ -4,6 +4,9 @@
|
||||
<span class="glyphicon glyphicon-user"></span> {{ .Username }}
|
||||
</a>
|
||||
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
|
||||
{{ if eq .AddNew true }}
|
||||
<li><a href="/add_new"><span class="glyphicon glyphicon-plus"></span> // 'add_new_title' | tr //</a></li>
|
||||
{{ end }}
|
||||
<li><a href="/account_setting"><span class="glyphicon glyphicon-pencil"></span> // 'account_setting' | tr //</a></li>
|
||||
<li class="dropdown-submenu">
|
||||
<a tabindex="-1" href="#"><span class="glyphicon glyphicon-globe"></span> //vm.languageName//</a>
|
||||
|
@ -56,6 +56,9 @@
|
||||
<script src="/static/resources/js/layout/sign-up/sign-up.module.js"></script>
|
||||
<script src="/static/resources/js/layout/sign-up/sign-up.controller.js"></script>
|
||||
|
||||
<script src="/static/resources/js/layout/add-new/add-new.module.js"></script>
|
||||
<script src="/static/resources/js/layout/add-new/add-new.controller.js"></script>
|
||||
|
||||
<script src="/static/resources/js/layout/account-setting/account-setting.module.js"></script>
|
||||
<script src="/static/resources/js/layout/account-setting/account-setting.controller.js"></script>
|
||||
|
||||
|
@ -32,10 +32,13 @@
|
||||
<div class="col-sm-offset-1 col-sm-10">
|
||||
<div class="pull-right">
|
||||
<button type="submit" class="btn btn-default" ng-click="vm.doSignIn(user)">// 'sign_in' | tr //</button>
|
||||
{{ if eq .AuthMode "db_auth" }}
|
||||
<button type="button" class="btn btn-success" ng-click="vm.doSignUp()">// 'sign_up' | tr //</button>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ if eq .AuthMode "db_auth" }}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-1 col-sm-10">
|
||||
<div class="pull-right">
|
||||
@ -43,5 +46,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</form>
|
||||
{{ end }}
|
@ -2,8 +2,18 @@
|
||||
<div class="container container-custom">
|
||||
<div class="row extend-height">
|
||||
<div class="section">
|
||||
{{ if eq .AddNew true }}
|
||||
<modal-dialog modal-title="// 'add_new_title' | tr //" modal-message="// 'successful_added' | tr //" confirm-only="true" action="vm.confirm()"></modal-dialog>
|
||||
{{ else }}
|
||||
<modal-dialog modal-title="// 'sign_up' | tr //" modal-message="// 'successful_signed_up' | tr //" confirm-only="true" action="vm.confirm()"></modal-dialog>
|
||||
<h1 class="col-md-12 col-md-offset-2 main-title title-color">// 'sign_up' | tr //</h1>
|
||||
{{ end }}
|
||||
<h1 class="col-md-12 col-md-offset-2 main-title title-color">
|
||||
{{ if eq .AddNew true }}
|
||||
// 'add_new_title' | tr //
|
||||
{{ else }}
|
||||
// 'sign_up' | tr //
|
||||
{{ end }}
|
||||
</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-md-offset-2 main-content">
|
||||
<form name="form" class="form-horizontal css-form" ng-submit="form.$valid">
|
||||
@ -90,7 +100,11 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-8 col-md-10">
|
||||
<input type="submit" class="btn btn-success" ng-disabled="form.$invalid" ng-click="vm.signUp(user)" value="Sign Up">
|
||||
{{ if eq .AddNew true }}
|
||||
<input type="submit" class="btn btn-success" ng-disabled="form.$invalid" ng-click="vm.signUp(user)" value="// 'add_new' | tr //">
|
||||
{{ else }}
|
||||
<input type="submit" class="btn btn-success" ng-disabled="form.$invalid" ng-click="vm.signUp(user)" value="// 'sign_up' | tr //">
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user