admin.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 AdminEditUserForm struct {
  14. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  15. Website string `form:"website" binding:"MaxSize(50)"`
  16. Location string `form:"location" binding:"MaxSize(50)"`
  17. Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
  18. Active bool `form:"active"`
  19. Admin bool `form:"admin"`
  20. LoginType int `form:"login_type"`
  21. }
  22. func (f *AdminEditUserForm) Name(field string) string {
  23. names := map[string]string{
  24. "Email": "E-mail address",
  25. "Website": "Website",
  26. "Location": "Location",
  27. "Avatar": "Gravatar Email",
  28. }
  29. return names[field]
  30. }
  31. func (f *AdminEditUserForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) {
  32. if req.Method == "GET" || errors.Count() == 0 {
  33. return
  34. }
  35. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  36. data["HasError"] = true
  37. AssignForm(f, data)
  38. if len(errors.Overall) > 0 {
  39. for _, err := range errors.Overall {
  40. log.Error("AdminEditUserForm.Validate: %v", err)
  41. }
  42. return
  43. }
  44. validate(errors, data, f)
  45. }