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.

144 lines
4.6 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. "mime/multipart"
  7. "github.com/go-macaron/binding"
  8. "gopkg.in/macaron.v1"
  9. )
  10. type InstallForm struct {
  11. DbType string `binding:"Required"`
  12. DbHost string
  13. DbUser string
  14. DbPasswd string
  15. DbName string
  16. SSLMode string
  17. DbPath string
  18. AppName string `binding:"Required" locale:"install.app_name"`
  19. RepoRootPath string `binding:"Required"`
  20. RunUser string `binding:"Required"`
  21. Domain string `binding:"Required"`
  22. SSHPort int
  23. HTTPPort string `binding:"Required"`
  24. AppUrl string `binding:"Required"`
  25. SMTPHost string
  26. SMTPFrom string
  27. SMTPEmail string `binding:"OmitEmpty;Email;MaxSize(254)" locale:"install.mailer_user"`
  28. SMTPPasswd string
  29. RegisterConfirm bool
  30. MailNotify bool
  31. OfflineMode bool
  32. DisableGravatar bool
  33. DisableRegistration bool
  34. EnableCaptcha bool
  35. RequireSignInView bool
  36. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  37. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  38. AdminConfirmPasswd string
  39. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  40. }
  41. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  42. return validate(errs, ctx.Data, f, ctx.Locale)
  43. }
  44. // _____ ____ _________________ ___
  45. // / _ \ | | \__ ___/ | \
  46. // / /_\ \| | / | | / ~ \
  47. // / | \ | / | | \ Y /
  48. // \____|__ /______/ |____| \___|_ /
  49. // \/ \/
  50. type RegisterForm struct {
  51. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  52. Email string `binding:"Required;Email;MaxSize(254)"`
  53. Password string `binding:"Required;MaxSize(255)"`
  54. Retype string
  55. }
  56. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  57. return validate(errs, ctx.Data, f, ctx.Locale)
  58. }
  59. type SignInForm struct {
  60. UserName string `binding:"Required;MaxSize(254)"`
  61. Password string `binding:"Required;MaxSize(255)"`
  62. Remember bool
  63. }
  64. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  65. return validate(errs, ctx.Data, f, ctx.Locale)
  66. }
  67. // __________________________________________.___ _______ ________ _________
  68. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  69. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  70. // / \ | \ | | | | | / | \ \_\ \/ \
  71. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  72. // \/ \/ \/ \/ \/
  73. type UpdateProfileForm struct {
  74. Name string `binding:"Required;MaxSize(35)"`
  75. FullName string `binding:"MaxSize(100)"`
  76. Email string `binding:"Required;Email;MaxSize(254)"`
  77. Website string `binding:"Url;MaxSize(100)"`
  78. Location string `binding:"MaxSize(50)"`
  79. Gravatar string `binding:"Required;Email;MaxSize(254)"`
  80. }
  81. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  82. return validate(errs, ctx.Data, f, ctx.Locale)
  83. }
  84. type UploadAvatarForm struct {
  85. Enable bool
  86. Avatar *multipart.FileHeader
  87. }
  88. func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  89. return validate(errs, ctx.Data, f, ctx.Locale)
  90. }
  91. type AddEmailForm struct {
  92. Email string `binding:"Required;Email;MaxSize(254)"`
  93. }
  94. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  95. return validate(errs, ctx.Data, f, ctx.Locale)
  96. }
  97. type ChangePasswordForm struct {
  98. OldPassword string `form:"old_password" binding:"Required;MinSize(1);MaxSize(255)"`
  99. Password string `form:"password" binding:"Required;MaxSize(255)"`
  100. Retype string `form:"retype"`
  101. }
  102. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  103. return validate(errs, ctx.Data, f, ctx.Locale)
  104. }
  105. type AddSSHKeyForm struct {
  106. Title string `binding:"Required;MaxSize(50)"`
  107. Content string `binding:"Required"`
  108. }
  109. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  110. return validate(errs, ctx.Data, f, ctx.Locale)
  111. }
  112. type NewAccessTokenForm struct {
  113. Name string `binding:"Required"`
  114. }
  115. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  116. return validate(errs, ctx.Data, f, ctx.Locale)
  117. }