admin.go 1.3 KB

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