authentication.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package auth
  5. import (
  6. "net/http"
  7. "reflect"
  8. "github.com/go-martini/martini"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/middleware/binding"
  11. )
  12. type AuthenticationForm struct {
  13. Id int64 `form:"id"`
  14. Type int `form:"type"`
  15. AuthName string `form:"name" binding:"Required;MaxSize(50)"`
  16. Domain string `form:"domain"`
  17. Host string `form:"host"`
  18. Port int `form:"port"`
  19. BaseDN string `form:"base_dn"`
  20. Attributes string `form:"attributes"`
  21. Filter string `form:"filter"`
  22. MsAdSA string `form:"ms_ad_sa"`
  23. IsActived bool `form:"is_actived"`
  24. SmtpAuth string `form:"smtpauth"`
  25. Tls bool `form:"tls"`
  26. AllowAutoRegister bool `form:"allowautoregister"`
  27. }
  28. func (f *AuthenticationForm) Name(field string) string {
  29. names := map[string]string{
  30. "AuthName": "Authentication's name",
  31. "Domain": "Domain name",
  32. "Host": "Host address",
  33. "Port": "Port Number",
  34. "BaseDN": "Base DN",
  35. "Attributes": "Search attributes",
  36. "Filter": "Search filter",
  37. "MsAdSA": "Ms Ad SA",
  38. }
  39. return names[field]
  40. }
  41. func (f *AuthenticationForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  42. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  43. validate(errors, data, f)
  44. }