1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

#697 and #1606 and new admin edit user UI

This commit is contained in:
Unknwon 2015-09-13 11:07:21 -04:00
parent e5ed5904c6
commit 83e747bfda
15 changed files with 183 additions and 156 deletions

View File

@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](public/img/gogs-large-resize.png)
##### Current version: 0.6.11 Beta
##### Current version: 0.6.12 Beta
<table>
<tr>

View File

@ -99,8 +99,8 @@ ENABLE_REVERSE_PROXY_AUTHENTICATION = false
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
; Do not check minimum key size with corresponding type
DISABLE_MINIMUM_KEY_SIZE_CHECK = false
; Disable captcha validation for registration
DISABLE_CAPTCHA = false
; Enable captcha validation for registration
ENABLE_CAPTCHA = true
[webhook]
; Hook task queue length

View File

@ -785,6 +785,7 @@ users.edit = Edit
users.auth_source = Authentication Source
users.local = Local
users.auth_login_name = Authentication Login Name
users.password_helper = Leave it empty to remain unchanged.
users.update_profile_success = Account profile has been updated successfully.
users.edit_account = Edit Account
users.is_activated = This account is activated

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.6.11.0913 Beta"
const APP_VER = "0.6.12.0913 Beta"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -10,17 +10,29 @@ import (
"github.com/macaron-contrib/binding"
)
type AdminCrateUserForm struct {
LoginType string `binding:"Required"`
LoginName string
UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
Email string `binding:"Required;Email;MaxSize(254)"`
Password string `binding:"MaxSize(255)"`
}
func (f *AdminCrateUserForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}
type AdminEditUserForm struct {
FullName string `form:"fullname" binding:"MaxSize(100)"`
LoginType string `binding:"Required"`
LoginName string
FullName string `binding:"MaxSize(100)"`
Email string `binding:"Required;Email;MaxSize(254)"`
Password string `binding:"OmitEmpty;MinSize(6);MaxSize(255)"`
Password string `binding:"MaxSize(255)"`
Website string `binding:"MaxSize(50)"`
Location string `binding:"MaxSize(50)"`
Avatar string `binding:"Required;Email;MaxSize(50)"`
Active bool
Admin bool
AllowGitHook bool
LoginType int
}
func (f *AdminEditUserForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {

View File

@ -78,18 +78,6 @@ func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding
return validate(errs, ctx.Data, f, ctx.Locale)
}
type AdminCrateUserForm struct {
UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
Email string `binding:"Required;Email;MaxSize(254)"`
Password string `binding:"MaxSize(255)"`
LoginType string
LoginName string
}
func (f *AdminCrateUserForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}
// __________________________________________.___ _______ ________ _________
// / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
// \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \

File diff suppressed because one or more lines are too long

View File

@ -421,7 +421,7 @@ var Service struct {
EnableReverseProxyAuth bool
EnableReverseProxyAutoRegister bool
DisableMinimumKeySizeCheck bool
DisableCaptcha bool
EnableCaptcha bool
}
func newService() {
@ -435,7 +435,7 @@ func newService() {
Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
Service.DisableMinimumKeySizeCheck = sec.Key("DISABLE_MINIMUM_KEY_SIZE_CHECK").MustBool()
Service.DisableCaptcha = sec.Key("DISABLE_CAPTCHA").MustBool()
Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
}
var logLevels = map[string]string{

View File

@ -458,20 +458,26 @@ function initAdmin() {
}
// New user
if ($('.admin.new.user').length > 0) {
if ($('.admin.new.user').length > 0 ||
$('.admin.edit.user').length > 0) {
$('#login_type').change(function () {
if ($(this).val().substring(0, 1) == '0') {
$('#login_name').removeAttr('required');
$('#password').attr('required', 'required');
$('.non-local').hide();
$('.local').show();
$('#user_name').focus();
if($(this).data('password')=="required"){
$('#password').attr('required', 'required');
}
} else {
$('#login_name').attr('required', 'required');
$('#password').removeAttr('required');
$('.non-local').show();
$('.local').hide();
$('#login_name').focus();
$('#password').removeAttr('required');
}
});
}

View File

@ -122,30 +122,44 @@ func NewUserPost(ctx *middleware.Context, form auth.AdminCrateUserForm) {
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + com.ToStr(u.Id))
}
func prepareUserInfo(ctx *middleware.Context) *models.User {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil {
ctx.Handle(500, "GetUserByID", err)
return nil
}
ctx.Data["User"] = u
if u.LoginSource > 0 {
ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource)
if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err)
return nil
}
} else {
ctx.Data["LoginSource"] = &models.LoginSource{}
}
sources, err := models.LoginSources()
if err != nil {
ctx.Handle(500, "LoginSources", err)
return nil
}
ctx.Data["Sources"] = sources
return u
}
func EditUser(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
uid := com.StrTo(ctx.Params(":userid")).MustInt64()
if uid == 0 {
ctx.Handle(404, "EditUser", nil)
prepareUserInfo(ctx)
if ctx.Written() {
return
}
u, err := models.GetUserByID(uid)
if err != nil {
ctx.Handle(500, "GetUserByID", err)
return
}
ctx.Data["User"] = u
sources, err := models.LoginSources()
if err != nil {
ctx.Handle(500, "LoginSources", err)
return
}
ctx.Data["LoginSources"] = sources
ctx.HTML(200, USER_EDIT)
}
@ -154,25 +168,28 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
uid := com.StrTo(ctx.Params(":userid")).MustInt64()
if uid == 0 {
ctx.Handle(404, "EditUser", nil)
u := prepareUserInfo(ctx)
if ctx.Written() {
return
}
u, err := models.GetUserByID(uid)
if err != nil {
ctx.Handle(500, "GetUserById", err)
return
}
ctx.Data["User"] = u
if ctx.HasError() {
ctx.HTML(200, USER_EDIT)
return
}
// FIXME: need password length check
fields := strings.Split(form.LoginType, "-")
if len(fields) == 2 {
loginType := models.LoginType(com.StrTo(fields[0]).MustInt())
loginSource := com.StrTo(fields[1]).MustInt64()
if u.LoginSource != loginSource {
u.LoginSource = loginSource
u.LoginType = loginType
u.LoginName = form.LoginName
}
}
if len(form.Password) > 0 {
u.Passwd = form.Password
u.Salt = models.GetUserSalt()
@ -183,11 +200,6 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
u.Email = form.Email
u.Website = form.Website
u.Location = form.Location
if len(form.Avatar) == 0 {
form.Avatar = form.Email
}
u.Avatar = base.EncodeMd5(form.Avatar)
u.AvatarEmail = form.Avatar
u.IsActive = form.Active
u.IsAdmin = form.Admin
u.AllowGitHook = form.AllowGitHook
@ -202,6 +214,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
return
}
log.Trace("Account profile updated by admin(%s): %s", ctx.User.Name, u.Name)
ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success"))
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
}

View File

@ -151,7 +151,7 @@ func oauthSignUp(ctx *middleware.Context, sid int64) {
func SignUp(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["DisableCaptcha"] = setting.Service.DisableCaptcha
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
if setting.Service.DisableRegistration {
ctx.Data["DisableRegistration"] = true
@ -170,7 +170,7 @@ func SignUp(ctx *middleware.Context) {
func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["DisableCaptcha"] = setting.Service.DisableCaptcha
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
if setting.Service.DisableRegistration {
ctx.Error(403)
@ -188,7 +188,7 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
return
}
if !setting.Service.DisableCaptcha && !cpt.VerifyReq(ctx.Req) {
if setting.Service.EnableCaptcha && !cpt.VerifyReq(ctx.Req) {
ctx.Data["Err_Captcha"] = true
ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), SIGNUP, &form)
return

View File

@ -1 +1 @@
0.6.11.0913 Beta
0.6.12.0913 Beta

View File

@ -1,93 +1,100 @@
{{template "ng/base/head" .}}
{{template "ng/base/header" .}}
<div id="admin-wrapper">
<div id="setting-wrapper" class="main-wrapper">
<div id="admin-setting" class="container clear">
{{template "admin/nav" .}}
<div class="grid-4-5 left">
<div class="setting-content">
{{template "ng/base/alert" .}}
<div id="setting-content">
<div class="panel panel-radius">
<div class="panel-header">
<strong>{{.i18n.Tr "admin.users.edit_account"}}</strong>
</div>
<form class="form form-align panel-body" id="user-profile-form" action="{{AppSubUrl}}/admin/users/{{.User.Id}}" method="post" data-delete-url="{{AppSubUrl}}/admin/users/{{.User.Id}}/delete">
{{.CsrfTokenHtml}}
<div class="field">
<label class="req">{{.i18n.Tr "admin.users.auth_source"}}</label>
<select id="login-type" name="logintype">
<option value="0-0">{{.i18n.Tr "admin.users.local"}}</option>
{{$tp := .User.LoginSource}}
{{range $key, $val := .LoginSources}}
<option value="{{$val.Type}}-{{$val.ID}}"{{if eq $val.ID $tp}} selected{{end}}>{{$val.Name}}</option>
{{end}}
</select>
</div>
<div class="field">
<label for="loginname">{{.i18n.Tr "admin.users.auth_login_name"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_LoginName}}ipt-error{{end}}" id="loginname" name="loginname" value="{{.User.LoginName}}" />
</div>
<div class="field">
<label>{{.i18n.Tr "username"}}</label>
<label class="text-left">{{.User.Name}}</label>
</div>
<div class="field">
<label for="full-name">{{.i18n.Tr "settings.full_name"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_FullName}}ipt-error{{end}}" id="full-name" name="fullname" type="text" value="{{.User.FullName}}" />
</div>
<div class="field">
<label class="req" for="email">{{.i18n.Tr "email"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_Email}}ipt-error{{end}}" id="email" name="email" type="email" value="{{.User.Email}}" required/>
</div>
<div class="field pwd">
<label for="password">{{.i18n.Tr "password"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_Password}}ipt-error{{end}}" id="password" name="password" type="password" />
</div>
<div class="field">
<label for="website">{{.i18n.Tr "settings.website"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_Website}}ipt-error{{end}}" id="website" name="website" type="url" value="{{.User.Website}}" />
</div>
<div class="field">
<label for="location">{{.i18n.Tr "settings.location"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_Location}}ipt-error{{end}}" id="location" name="location" type="text" value="{{.User.Location}}" />
</div>
<div class="field">
<label for="gravatar-email">Gravatar {{.i18n.Tr "email"}}</label>
<input class="ipt ipt-large ipt-radius {{if .Err_Avatar}}ipt-error{{end}}" id="gravatar-email" name="avatar" type="text" value="{{.User.AvatarEmail}}" />
</div>
<div class="field">
<label></label>
<input type="checkbox" name="active" {{if .User.IsActive}}checked{{end}}>
<strong>{{.i18n.Tr "admin.users.is_activated"}}</strong>
<br>
<label></label>
<input type="checkbox" name="admin" {{if .User.IsAdmin}}checked{{end}}>
<strong>{{.i18n.Tr "admin.users.is_admin"}}</strong>
<br>
<label></label>
<input type="checkbox" name="allow_git_hook" {{if .User.AllowGitHook}}checked{{end}}>
<strong>{{.i18n.Tr "admin.users.allow_git_hook"}}</strong>
</div>
<div class="field">
<label></label>
<button class="btn btn-green btn-large btn-radius">{{.i18n.Tr "admin.users.update_profile"}}</button>
&nbsp;&nbsp;&nbsp;&nbsp;
<button class="btn btn-large btn-red btn-radius" id="delete-account-btn" href="#delete-account-modal">{{.i18n.Tr "admin.users.delete_account"}}</button>
</div>
<div class="white-popup-block mfp-hide" id="delete-account-modal">
<h1 class="text-red">{{.i18n.Tr "settings.delete_account_title"}}</h1>
<p>{{.i18n.Tr "settings.delete_account_desc"}}</p>
<br>
<button class="btn btn-red btn-large btn-radius" id="delete-account-submit">{{.i18n.Tr "settings.continue"}}</button>
<button class="btn btn-large btn-radius popup-modal-dismiss">{{.i18n.Tr "settings.cancel"}}</button>
</div>
</form>
</div>
</div>
</div>
{{template "base/head" .}}
<div class="admin edit user">
<div class="ui container">
<div class="ui grid">
{{template "admin/navbar" .}}
<div class="twelve wide column content">
{{template "base/alert" .}}
<h4 class="ui top attached header">
{{.i18n.Tr "admin.users.edit_account"}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div class="inline field {{if .Err_UserName}}error{{end}}">
<label for="user_name">{{.i18n.Tr "username"}}</label>
<span>{{.User.Name}}</span>
</div>
<!-- Types and name -->
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
<label>{{.i18n.Tr "admin.users.auth_source"}}</label>
<div class="ui selection type dropdown">
<input type="hidden" id="login_type" name="login_type" value="{{.LoginSource.Type}}-{{.LoginSource.ID}}" required>
<div class="text">{{.i18n.Tr "admin.users.local"}}</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="0-0">{{.i18n.Tr "admin.users.local"}}</div>
{{range .Sources}}
<div class="item" data-value="{{.Type}}-{{.ID}}">{{.Name}}</div>
{{end}}
</div>
</div>
</div>
<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .User.LoginSource 0}}hide{{end}}">
<label for="login_name">{{.i18n.Tr "admin.users.auth_login_name"}}</label>
<input id="login_name" name="login_name" value="{{.User.LoginName}}" autofocus>
</div>
<div class="field {{if .Err_FullName}}error{{end}}">
<label for="full_name">{{.i18n.Tr "settings.full_name"}}</label>
<input id="full_name" name="full_name" value="{{.User.FullName}}">
</div>
<div class="required field {{if .Err_Email}}error{{end}}">
<label for="email">{{.i18n.Tr "email"}}</label>
<input id="email" name="email" type="email" value="{{.User.Email}}" autofocus required>
</div>
<input class="fake" type="password">
<div class="local field {{if .Err_Password}}error{{end}} {{if not (eq .User.LoginSource 0)}}hide{{end}}">
<label for="password">{{.i18n.Tr "password"}}</label>
<input id="password" name="password" type="password">
<p class="help">{{.i18n.Tr "admin.users.password_helper"}}</p>
</div>
<div class="field {{if .Err_Website}}error{{end}}">
<label for="website">{{.i18n.Tr "settings.website"}}</label>
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="e.g. http://mydomain.com or https://mydomain.com">
</div>
<div class="field {{if .Err_Location}}error{{end}}">
<label for="location">{{.i18n.Tr "settings.location"}}</label>
<input id="location" name="location" value="{{.User.Location}}">
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.is_activated"}}</strong></label>
<input name="active" type="checkbox" {{if .User.IsActive}}checked{{end}}>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.is_admin"}}</strong></label>
<input name="admin" type="checkbox" {{if .User.IsAdmin}}checked{{end}}>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.allow_git_hook"}}</strong></label>
<input name="allow_git_hook" type="checkbox" {{if or .User.IsAdmin .User.AllowGitHook}}checked{{end}}>
</div>
</div>
<div class="field">
<button class="ui green button">{{.i18n.Tr "admin.users.update_profile"}}</button>
<div class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.User.Id}}">{{.i18n.Tr "admin.users.delete_account"}}</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{{template "ng/base/footer" .}}
<div class="ui small basic delete modal">
<div class="ui icon header">
<i class="trash icon"></i>
{{.i18n.Tr "settings.delete_account_title"}}
</div>
<div class="content">
<p>{{.i18n.Tr "settings.delete_account_desc"}}</p>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{template "base/footer" .}}

View File

@ -15,7 +15,7 @@
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
<label>{{.i18n.Tr "admin.users.auth_source"}}</label>
<div class="ui selection type dropdown">
<input type="hidden" id="login_type" name="login_type" value="{{.login_type}}" required>
<input type="hidden" id="login_type" name="login_type" value="{{.login_type}}" data-password="required" required>
<div class="text">{{.i18n.Tr "admin.users.local"}}</div>
<i class="dropdown icon"></i>
<div class="menu">

View File

@ -28,7 +28,7 @@
<label for="retype">{{.i18n.Tr "re_type"}}</label>
<input id="retype" name="retype" type="password" value="{{.retype}}" required>
</div>
{{if not .DisableCaptcha}}
{{if .EnableCaptcha}}
<div class="inline field">
<label></label>
{{.Captcha.CreateHtml}}