mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 23:03:34 +01:00
fix code
This commit is contained in:
parent
d8136c9c3c
commit
3b7465f817
9 changed files with 155 additions and 95 deletions
|
@ -1,3 +1,7 @@
|
|||
// Copyright github.com/juju2013. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -7,6 +11,7 @@ import (
|
|||
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
|
||||
"github.com/gogits/gogs/modules/auth/ldap"
|
||||
)
|
||||
|
||||
|
@ -19,7 +24,7 @@ const (
|
|||
|
||||
var (
|
||||
ErrAuthenticationAlreadyExist = errors.New("Authentication already exist")
|
||||
ErrAuthenticationNotExist = errors.New("Authentication is not exist")
|
||||
ErrAuthenticationNotExist = errors.New("Authentication does not exist")
|
||||
ErrAuthenticationUserUsed = errors.New("Authentication has been used by some users")
|
||||
)
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ type AdminEditUserForm struct {
|
|||
Website string `form:"website" binding:"MaxSize(50)"`
|
||||
Location string `form:"location" binding:"MaxSize(50)"`
|
||||
Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
|
||||
Active string `form:"active"`
|
||||
Admin string `form:"admin"`
|
||||
Active bool `form:"active"`
|
||||
Admin bool `form:"admin"`
|
||||
LoginType int `form:"login_type"`
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,63 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware/binding"
|
||||
)
|
||||
|
||||
type AuthenticationForm struct {
|
||||
Id int64 `form:"id"`
|
||||
Type int `form:"type"`
|
||||
Name string `form:"name" binding:"MaxSize(50)"`
|
||||
Domain string `form:"domain"`
|
||||
Host string `form:"host"`
|
||||
Port int `form:"port"`
|
||||
BaseDN string `form:"base_dn"`
|
||||
Attributes string `form:"attributes"`
|
||||
Filter string `form:"filter"`
|
||||
MsAdSA string `form:"ms_ad_sa"`
|
||||
AuthName string `form:"name" binding:"Required;MaxSize(50)"`
|
||||
Domain string `form:"domain" binding:"Required"`
|
||||
Host string `form:"host" binding:"Required"`
|
||||
Port int `form:"port" binding:"Required"`
|
||||
BaseDN string `form:"base_dn" binding:"Required"`
|
||||
Attributes string `form:"attributes" binding:"Required"`
|
||||
Filter string `form:"filter" binding:"Required"`
|
||||
MsAdSA string `form:"ms_ad_sa" binding:"Required"`
|
||||
IsActived bool `form:"is_actived"`
|
||||
}
|
||||
|
||||
func (f *AuthenticationForm) Name(field string) string {
|
||||
names := map[string]string{
|
||||
"AuthName": "Authentication's name",
|
||||
"Domain": "Domain name",
|
||||
"Host": "Host address",
|
||||
"Port": "Port Number",
|
||||
"BaseDN": "Base DN",
|
||||
"Attributes": "Search attributes",
|
||||
"Filter": "Search filter",
|
||||
"MsAdSA": "Ms Ad SA",
|
||||
}
|
||||
return names[field]
|
||||
}
|
||||
|
||||
func (f *AuthenticationForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) {
|
||||
if req.Method == "GET" || errors.Count() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
|
||||
data["HasError"] = true
|
||||
AssignForm(f, data)
|
||||
|
||||
if len(errors.Overall) > 0 {
|
||||
for _, err := range errors.Overall {
|
||||
log.Error("AuthenticationForm.Validate: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
validate(errors, data, f)
|
||||
}
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/auth/ldap"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gpmgo/gopm/log"
|
||||
)
|
||||
|
||||
func NewAuthSource(ctx *middleware.Context) {
|
||||
|
@ -37,11 +42,11 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
Filter: form.Filter,
|
||||
MsAdSAFormat: form.MsAdSA,
|
||||
Enabled: true,
|
||||
Name: form.Name,
|
||||
Name: form.AuthName,
|
||||
},
|
||||
}
|
||||
|
||||
if err := models.AddLDAPSource(form.Name, u); err != nil {
|
||||
if err := models.AddLDAPSource(form.AuthName, u); err != nil {
|
||||
switch err {
|
||||
default:
|
||||
ctx.Handle(500, "admin.auths.NewAuth", err)
|
||||
|
@ -50,7 +55,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
}
|
||||
|
||||
log.Trace("%s Authentication created by admin(%s): %s", ctx.Req.RequestURI,
|
||||
ctx.User.LowerName, strings.ToLower(form.Name))
|
||||
ctx.User.LowerName, strings.ToLower(form.AuthName))
|
||||
|
||||
ctx.Redirect("/admin/auths")
|
||||
}
|
||||
|
@ -83,7 +88,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
}
|
||||
|
||||
u := models.LoginSource{
|
||||
Name: form.Name,
|
||||
Name: form.AuthName,
|
||||
IsActived: form.IsActived,
|
||||
Type: models.LT_LDAP,
|
||||
Cfg: &models.LDAPConfig{
|
||||
|
@ -95,7 +100,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
Filter: form.Filter,
|
||||
MsAdSAFormat: form.MsAdSA,
|
||||
Enabled: true,
|
||||
Name: form.Name,
|
||||
Name: form.AuthName,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -109,7 +114,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
}
|
||||
|
||||
log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI,
|
||||
ctx.User.LowerName, strings.ToLower(form.Name))
|
||||
ctx.User.LowerName, strings.ToLower(form.AuthName))
|
||||
|
||||
ctx.Redirect("/admin/auths")
|
||||
}
|
||||
|
|
|
@ -130,9 +130,8 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi
|
|||
u.Location = form.Location
|
||||
u.Avatar = base.EncodeMd5(form.Avatar)
|
||||
u.AvatarEmail = form.Avatar
|
||||
u.IsActive = form.Active == "on"
|
||||
u.IsAdmin = form.Admin == "on"
|
||||
u.LoginType = form.LoginType
|
||||
u.IsActive = form.Active
|
||||
u.IsAdmin = form.Admin
|
||||
if err := models.UpdateUser(u); err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser", err)
|
||||
return
|
||||
|
|
|
@ -15,69 +15,70 @@
|
|||
{{template "base/alert" .}}
|
||||
<input type="hidden" value="{{.Source.Id}}" name="id"/>
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Auth Type: </label>
|
||||
<div class="col-md-7">
|
||||
<select class="form-control">
|
||||
{{$type := .Source.Type}}
|
||||
{{range $key, $val := .LoginTypes}}
|
||||
<option value="{{$key}}" {{if eq $key $type}}selected{{end}}>{{$val}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Auth Type: </label>
|
||||
<div class="col-md-7">
|
||||
<select class="form-control">
|
||||
{{$type := .Source.Type}}
|
||||
{{range $key, $val := .LoginTypes}}
|
||||
<option value="{{$key}}" {{if eq $key $type}}selected{{end}}>{{$val}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_AuthName}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Name: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="name" class="form-control" placeholder="Type account's username" value="{{.Source.Name}}" required="required">
|
||||
<input name="name" class="form-control" placeholder="Type authentication's name" value="{{.Source.Name}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Domain}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Domain: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="domain" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.Name}}" required="required" title="Email is not valid">
|
||||
<input name="domain" class="form-control" placeholder="Type domain name" value="{{.Source.LDAP.Name}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Host}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Host: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="host" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.Host}}" required="required" title="Email is not valid">
|
||||
<input name="host" class="form-control" placeholder="Type host address" value="{{.Source.LDAP.Host}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Port}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Port: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="port" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.Port}}" required="required" title="Email is not valid">
|
||||
<input name="port" class="form-control" placeholder="Type port number" value="{{.Source.LDAP.Port}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_BaseDN}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Base DN: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="base_dn" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.BaseDN}}" required="required" title="Email is not valid">
|
||||
<input name="base_dn" class="form-control" placeholder="Type base DN" value="{{.Source.LDAP.BaseDN}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Attributes}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Search Attributes: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="attributes" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.Attributes}}" required="required" title="Email is not valid">
|
||||
<input name="attributes" class="form-control" placeholder="Type search attributes" value="{{.Source.LDAP.Attributes}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Filter}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Search Filter: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="filter" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.Filter}}" required="required" title="Email is not valid">
|
||||
<input name="filter" class="form-control" placeholder="Type search filter" value="{{.Source.LDAP.Filter}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_MsAdSA}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Ms Ad SA: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="ms_ad_sa" class="form-control" placeholder="Type account's e-mail address" value="{{.Source.LDAP.MsAdSAFormat}}" required="required" title="Email is not valid">
|
||||
<input name="ms_ad_sa" class="form-control" placeholder="Type Ms Ad SA" value="{{.Source.LDAP.MsAdSAFormat}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -14,68 +14,69 @@
|
|||
{{.CsrfTokenHtml}}
|
||||
{{template "base/alert" .}}
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Auth Type: </label>
|
||||
<div class="col-md-7">
|
||||
<select class="form-control">
|
||||
{{range $key, $val := .LoginTypes}}
|
||||
<option value="{{$key}}">{{$val}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Auth Type: </label>
|
||||
<div class="col-md-7">
|
||||
<select class="form-control">
|
||||
{{range $key, $val := .LoginTypes}}
|
||||
<option value="{{$key}}">{{$val}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_AuthName}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Name: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="name" class="form-control" placeholder="Authentication's name" required="required">
|
||||
<input name="name" class="form-control" placeholder="Type authentication's name" value="{{.name}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Domain}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Domain: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="domain" class="form-control" placeholder="Domain name" value="{{.domain}}" required="required" title="Email is not valid">
|
||||
<input name="domain" class="form-control" placeholder="Type domain name" value="{{.domain}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Host}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Host: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="host" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="host" class="form-control" placeholder="Type host address" value="{{.host}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Port}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Port: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="port" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="port" class="form-control" placeholder="Type port number" value="{{.port}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_BaseDN}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Base DN: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="base_dn" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="base_dn" class="form-control" placeholder="Type base DN" value="{{.base_dn}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Attributes}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Search Attributes: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="attributes" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="attributes" class="form-control" placeholder="Type search attributes" value="{{.attributes}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_Filter}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Search Filter: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="filter" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="filter" class="form-control" placeholder="Type search filter" value="{{.filter}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
|
||||
<div class="form-group {{if .Err_MsAdSA}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Ms Ad SA: </label>
|
||||
<div class="col-md-7">
|
||||
<input name="ms_ad_sa" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid">
|
||||
<input name="ms_ad_sa" class="form-control" placeholder="Type Ms Ad SA" value="{{.ms_ad_sa}}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -13,19 +13,19 @@
|
|||
<form action="/admin/users/{{.User.Id}}" method="post" class="form-horizontal">
|
||||
{{.CsrfTokenHtml}}
|
||||
{{template "base/alert" .}}
|
||||
<input type="hidden" value="{{.User.Id}}" name="userId"/>
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Auth Source: </label>
|
||||
<div class="col-md-7">
|
||||
<select name="logintype" class="form-control">
|
||||
<option value="0-0"{{if eq 0 .User.LoginSource}} selected{{end}}>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>
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Auth Source: </label>
|
||||
<div class="col-md-7">
|
||||
<select name="logintype" class="form-control">
|
||||
<option value="0-0"{{if eq 0 .User.LoginSource}} selected{{end}}>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>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Username: </label>
|
||||
<label class="control-label">{{.User.Name}}</label>
|
||||
|
|
|
@ -14,16 +14,17 @@
|
|||
{{.CsrfTokenHtml}}
|
||||
{{template "base/alert" .}}
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">Auth Source: </label>
|
||||
<div class="col-md-7">
|
||||
<select name="logintype" class="form-control">
|
||||
<option value="0-0">Local</option>
|
||||
{{range $key, $val := .LoginSources}}
|
||||
<option value="{{$val.Type}}-{{$val.Id}}">{{$val.Name}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<label class="col-md-3 control-label">Auth Source: </label>
|
||||
<div class="col-md-7">
|
||||
<select name="logintype" class="form-control">
|
||||
<option value="0-0">Local</option>
|
||||
{{range $key, $val := .LoginSources}}
|
||||
<option value="{{$val.Type}}-{{$val.Id}}">{{$val.Name}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}">
|
||||
<label class="col-md-3 control-label">Username: </label>
|
||||
<div class="col-md-7">
|
||||
|
|
Loading…
Reference in a new issue