]> source.dussan.org Git - gitea.git/commitdiff
fix code
authorUnknown <joe2010xtmf@163.com>
Mon, 5 May 2014 09:32:47 +0000 (05:32 -0400)
committerUnknown <joe2010xtmf@163.com>
Mon, 5 May 2014 09:32:47 +0000 (05:32 -0400)
models/login.go
modules/auth/admin.go
modules/auth/authentication.go
routers/admin/auths.go
routers/admin/user.go
templates/admin/auths/edit.tmpl
templates/admin/auths/new.tmpl
templates/admin/users/edit.tmpl
templates/admin/users/new.tmpl

index d5905eb36b3a20a8d29965c1e93f8cab0d3abdcb..21e1ce686ae9b2b535f1b82b54c9fba642448774 100644 (file)
@@ -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")
 )
 
index c82fa7815023031286cf347a0c73590ccc581535..39d2d09620044e0de3074cb751cd9864891efea7 100644 (file)
@@ -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"`
 }
 
index d9c61b9d79f529eef3d527e591ca36b43606cf20..376a52e9a7b546a1ed4069f003eb7db5f34f5732 100644 (file)
@@ -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)
+}
index 892413049e1d809b0b1acd66ee0f4a99379bb45c..40318c3d2491b0b83de0536f2dd1f40eb50911c4 100644 (file)
@@ -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")
 }
index 14c17e9756aba75c66800b6795ed70ed8ddde42e..f2e1b0473001310386a0998d62258c1244cf1346 100644 (file)
@@ -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
index 1a2548fbebcf6801b8d3a2c591ba6f9cf389eec9..e040ea8f7753fee78cadc6bcd73e05e4f3972694 100644 (file)
                     {{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>
                     
index a5da93bd2aadedb03d906763a401c4c93074488f..1ed23569e4298e78690a13028100a18df622b845 100644 (file)
                                        {{.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>
                                        
index 9c9c36a28c14b9a3af3aae4a19c82051bd0d2355..1fb29234ed8fa2de23c479a19b89a30e0f32f14f 100644 (file)
                                <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>
index c19cd53c0afc42bb0bc886732b2957bcc36a979e..88da16aa4e235ff6de9fb645a69ba1e178e80701 100644 (file)
                                        {{.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">