authentication.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/log"
  11. "github.com/gogits/gogs/modules/middleware/binding"
  12. )
  13. type AuthenticationForm struct {
  14. Id int64 `form:"id"`
  15. Type int `form:"type"`
  16. AuthName string `form:"name" binding:"Required;MaxSize(50)"`
  17. Domain string `form:"domain" binding:"Required"`
  18. Host string `form:"host" binding:"Required"`
  19. Port int `form:"port" binding:"Required"`
  20. BaseDN string `form:"base_dn" binding:"Required"`
  21. Attributes string `form:"attributes" binding:"Required"`
  22. Filter string `form:"filter" binding:"Required"`
  23. MsAdSA string `form:"ms_ad_sa" binding:"Required"`
  24. IsActived bool `form:"is_actived"`
  25. }
  26. func (f *AuthenticationForm) Name(field string) string {
  27. names := map[string]string{
  28. "AuthName": "Authentication's name",
  29. "Domain": "Domain name",
  30. "Host": "Host address",
  31. "Port": "Port Number",
  32. "BaseDN": "Base DN",
  33. "Attributes": "Search attributes",
  34. "Filter": "Search filter",
  35. "MsAdSA": "Ms Ad SA",
  36. }
  37. return names[field]
  38. }
  39. func (f *AuthenticationForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) {
  40. if req.Method == "GET" || errors.Count() == 0 {
  41. return
  42. }
  43. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  44. data["HasError"] = true
  45. AssignForm(f, data)
  46. if len(errors.Overall) > 0 {
  47. for _, err := range errors.Overall {
  48. log.Error("AuthenticationForm.Validate: %v", err)
  49. }
  50. return
  51. }
  52. validate(errors, data, f)
  53. }