Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

user_form.go 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. // InstallForm form for installation page
  11. type InstallForm struct {
  12. DbType string `binding:"Required"`
  13. DbHost string
  14. DbUser string
  15. DbPasswd string
  16. DbName string
  17. SSLMode string
  18. DbPath string
  19. AppName string `binding:"Required" locale:"install.app_name"`
  20. RepoRootPath string `binding:"Required"`
  21. LFSRootPath string
  22. RunUser string `binding:"Required"`
  23. Domain string `binding:"Required"`
  24. SSHPort int
  25. HTTPPort string `binding:"Required"`
  26. AppURL string `binding:"Required"`
  27. LogRootPath string `binding:"Required"`
  28. SMTPHost string
  29. SMTPFrom string
  30. SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
  31. SMTPPasswd string
  32. RegisterConfirm bool
  33. MailNotify bool
  34. OfflineMode bool
  35. DisableGravatar bool
  36. EnableFederatedAvatar bool
  37. EnableOpenIDSignIn bool
  38. EnableOpenIDSignUp bool
  39. DisableRegistration bool
  40. EnableCaptcha bool
  41. RequireSignInView bool
  42. DefaultKeepEmailPrivate bool
  43. DefaultAllowCreateOrganization bool
  44. DefaultEnableTimetracking bool
  45. NoReplyAddress string
  46. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  47. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  48. AdminConfirmPasswd string
  49. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  50. }
  51. // Validate validates the fields
  52. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  53. return validate(errs, ctx.Data, f, ctx.Locale)
  54. }
  55. // _____ ____ _________________ ___
  56. // / _ \ | | \__ ___/ | \
  57. // / /_\ \| | / | | / ~ \
  58. // / | \ | / | | \ Y /
  59. // \____|__ /______/ |____| \___|_ /
  60. // \/ \/
  61. // RegisterForm form for registering
  62. type RegisterForm struct {
  63. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  64. Email string `binding:"Required;Email;MaxSize(254)"`
  65. Password string `binding:"Required;MaxSize(255)"`
  66. Retype string
  67. }
  68. // Validate valideates the fields
  69. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  70. return validate(errs, ctx.Data, f, ctx.Locale)
  71. }
  72. // SignInForm form for signing in with user/password
  73. type SignInForm struct {
  74. UserName string `binding:"Required;MaxSize(254)"`
  75. Password string `binding:"Required;MaxSize(255)"`
  76. Remember bool
  77. }
  78. // Validate valideates the fields
  79. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  80. return validate(errs, ctx.Data, f, ctx.Locale)
  81. }
  82. // __________________________________________.___ _______ ________ _________
  83. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  84. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  85. // / \ | \ | | | | | / | \ \_\ \/ \
  86. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  87. // \/ \/ \/ \/ \/
  88. // UpdateProfileForm form for updating profile
  89. type UpdateProfileForm struct {
  90. Name string `binding:"AlphaDashDot;MaxSize(35)"`
  91. FullName string `binding:"MaxSize(100)"`
  92. Email string `binding:"Required;Email;MaxSize(254)"`
  93. KeepEmailPrivate bool
  94. Website string `binding:"ValidUrl;MaxSize(255)"`
  95. Location string `binding:"MaxSize(50)"`
  96. }
  97. // Validate validates the fields
  98. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  99. return validate(errs, ctx.Data, f, ctx.Locale)
  100. }
  101. // Avatar types
  102. const (
  103. AvatarLocal string = "local"
  104. AvatarByMail string = "bymail"
  105. )
  106. // AvatarForm form for changing avatar
  107. type AvatarForm struct {
  108. Source string
  109. Avatar *multipart.FileHeader
  110. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  111. Federavatar bool
  112. }
  113. // Validate validates the fields
  114. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  115. return validate(errs, ctx.Data, f, ctx.Locale)
  116. }
  117. // AddEmailForm form for adding new email
  118. type AddEmailForm struct {
  119. Email string `binding:"Required;Email;MaxSize(254)"`
  120. }
  121. // Validate validates the fields
  122. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  123. return validate(errs, ctx.Data, f, ctx.Locale)
  124. }
  125. // ChangePasswordForm form for changing password
  126. type ChangePasswordForm struct {
  127. OldPassword string `form:"old_password" binding:"MaxSize(255)"`
  128. Password string `form:"password" binding:"Required;MaxSize(255)"`
  129. Retype string `form:"retype"`
  130. }
  131. // Validate validates the fields
  132. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  133. return validate(errs, ctx.Data, f, ctx.Locale)
  134. }
  135. // AddOpenIDForm is for changing openid uri
  136. type AddOpenIDForm struct {
  137. Openid string `binding:"Required;MaxSize(256)"`
  138. }
  139. // Validate validates the fields
  140. func (f *AddOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  141. return validate(errs, ctx.Data, f, ctx.Locale)
  142. }
  143. // AddKeyForm form for adding SSH/GPG key
  144. type AddKeyForm struct {
  145. Type string `binding:"OmitEmpty"`
  146. Title string `binding:"Required;MaxSize(50)"`
  147. Content string `binding:"Required"`
  148. }
  149. // Validate validates the fields
  150. func (f *AddKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  151. return validate(errs, ctx.Data, f, ctx.Locale)
  152. }
  153. // NewAccessTokenForm form for creating access token
  154. type NewAccessTokenForm struct {
  155. Name string `binding:"Required"`
  156. }
  157. // Validate valideates the fields
  158. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  159. return validate(errs, ctx.Data, f, ctx.Locale)
  160. }
  161. // TwoFactorAuthForm for logging in with 2FA token.
  162. type TwoFactorAuthForm struct {
  163. Passcode string `binding:"Required"`
  164. }
  165. // Validate validates the fields
  166. func (f *TwoFactorAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  167. return validate(errs, ctx.Data, f, ctx.Locale)
  168. }
  169. // TwoFactorScratchAuthForm for logging in with 2FA scratch token.
  170. type TwoFactorScratchAuthForm struct {
  171. Token string `binding:"Required"`
  172. }
  173. // Validate valideates the fields
  174. func (f *TwoFactorScratchAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  175. return validate(errs, ctx.Data, f, ctx.Locale)
  176. }