You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  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/binding"
  10. "github.com/gogits/gogs/modules/base"
  11. "github.com/gogits/gogs/modules/log"
  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 string `form:"active"`
  19. Admin string `form:"admin"`
  20. }
  21. func (f *AdminEditUserForm) Name(field string) string {
  22. names := map[string]string{
  23. "Email": "E-mail address",
  24. "Website": "Website",
  25. "Location": "Location",
  26. "Avatar": "Gravatar Email",
  27. }
  28. return names[field]
  29. }
  30. func (f *AdminEditUserForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  31. if req.Method == "GET" || errors.Count() == 0 {
  32. return
  33. }
  34. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  35. data["HasError"] = true
  36. AssignForm(f, data)
  37. if len(errors.Overall) > 0 {
  38. for _, err := range errors.Overall {
  39. log.Error("AdminEditUserForm.Validate: %v", err)
  40. }
  41. return
  42. }
  43. validate(errors, data, f)
  44. }