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.

admin.go 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 forms
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/modules/web/middleware"
  10. "gitea.com/go-chi/binding"
  11. )
  12. // AdminCreateUserForm form for admin to create user
  13. type AdminCreateUserForm struct {
  14. LoginType string `binding:"Required"`
  15. LoginName string
  16. UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
  17. Email string `binding:"Required;Email;MaxSize(254)"`
  18. Password string `binding:"MaxSize(255)"`
  19. SendNotify bool
  20. MustChangePassword bool
  21. Visibility structs.VisibleType
  22. }
  23. // Validate validates form fields
  24. func (f *AdminCreateUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  25. ctx := context.GetContext(req)
  26. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  27. }
  28. // AdminEditUserForm form for admin to create user
  29. type AdminEditUserForm struct {
  30. LoginType string `binding:"Required"`
  31. UserName string `binding:"AlphaDashDot;MaxSize(40)"`
  32. LoginName string
  33. FullName string `binding:"MaxSize(100)"`
  34. Email string `binding:"Required;Email;MaxSize(254)"`
  35. Password string `binding:"MaxSize(255)"`
  36. Website string `binding:"ValidUrl;MaxSize(255)"`
  37. Location string `binding:"MaxSize(50)"`
  38. MaxRepoCreation int
  39. Active bool
  40. Admin bool
  41. Restricted bool
  42. AllowGitHook bool
  43. AllowImportLocal bool
  44. AllowCreateOrganization bool
  45. ProhibitLogin bool
  46. Reset2FA bool `form:"reset_2fa"`
  47. Visibility structs.VisibleType
  48. }
  49. // Validate validates form fields
  50. func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  51. ctx := context.GetContext(req)
  52. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  53. }
  54. // AdminDashboardForm form for admin dashboard operations
  55. type AdminDashboardForm struct {
  56. Op string `binding:"required"`
  57. From string
  58. }
  59. // Validate validates form fields
  60. func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  61. ctx := context.GetContext(req)
  62. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  63. }