Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

user_form.go 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. DisableRegistration bool
  38. EnableCaptcha bool
  39. RequireSignInView bool
  40. DefaultKeepEmailPrivate bool
  41. NoReplyAddress string
  42. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  43. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  44. AdminConfirmPasswd string
  45. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  46. }
  47. // Validate validates the fields
  48. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  49. return validate(errs, ctx.Data, f, ctx.Locale)
  50. }
  51. // _____ ____ _________________ ___
  52. // / _ \ | | \__ ___/ | \
  53. // / /_\ \| | / | | / ~ \
  54. // / | \ | / | | \ Y /
  55. // \____|__ /______/ |____| \___|_ /
  56. // \/ \/
  57. // RegisterForm form for registering
  58. type RegisterForm struct {
  59. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  60. Email string `binding:"Required;Email;MaxSize(254)"`
  61. Password string `binding:"Required;MaxSize(255)"`
  62. Retype string
  63. }
  64. // Validate valideates the fields
  65. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  66. return validate(errs, ctx.Data, f, ctx.Locale)
  67. }
  68. // SignInForm form for signing in
  69. type SignInForm struct {
  70. UserName string `binding:"Required;MaxSize(254)"`
  71. Password string `binding:"Required;MaxSize(255)"`
  72. Remember bool
  73. }
  74. // Validate valideates the fields
  75. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  76. return validate(errs, ctx.Data, f, ctx.Locale)
  77. }
  78. // __________________________________________.___ _______ ________ _________
  79. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  80. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  81. // / \ | \ | | | | | / | \ \_\ \/ \
  82. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  83. // \/ \/ \/ \/ \/
  84. // UpdateProfileForm form for updating profile
  85. type UpdateProfileForm struct {
  86. Name string `binding:"OmitEmpty;MaxSize(35)"`
  87. FullName string `binding:"MaxSize(100)"`
  88. Email string `binding:"Required;Email;MaxSize(254)"`
  89. KeepEmailPrivate bool
  90. Website string `binding:"Url;MaxSize(255)"`
  91. Location string `binding:"MaxSize(50)"`
  92. }
  93. // Validate validates the fields
  94. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  95. return validate(errs, ctx.Data, f, ctx.Locale)
  96. }
  97. // Avatar types
  98. const (
  99. AvatarLocal string = "local"
  100. AvatarByMail string = "bymail"
  101. )
  102. // AvatarForm form for changing avatar
  103. type AvatarForm struct {
  104. Source string
  105. Avatar *multipart.FileHeader
  106. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  107. Federavatar bool
  108. }
  109. // Validate validates the fields
  110. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  111. return validate(errs, ctx.Data, f, ctx.Locale)
  112. }
  113. // AddEmailForm form for adding new email
  114. type AddEmailForm struct {
  115. Email string `binding:"Required;Email;MaxSize(254)"`
  116. }
  117. // Validate validates the fields
  118. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  119. return validate(errs, ctx.Data, f, ctx.Locale)
  120. }
  121. // ChangePasswordForm form for changing password
  122. type ChangePasswordForm struct {
  123. OldPassword string `form:"old_password" binding:"MaxSize(255)"`
  124. Password string `form:"password" binding:"Required;MaxSize(255)"`
  125. Retype string `form:"retype"`
  126. }
  127. // Validate validates the fields
  128. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  129. return validate(errs, ctx.Data, f, ctx.Locale)
  130. }
  131. // AddSSHKeyForm form for adding SSH key
  132. type AddSSHKeyForm struct {
  133. Title string `binding:"Required;MaxSize(50)"`
  134. Content string `binding:"Required"`
  135. }
  136. // Validate validates the fields
  137. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  138. return validate(errs, ctx.Data, f, ctx.Locale)
  139. }
  140. // NewAccessTokenForm form for creating access token
  141. type NewAccessTokenForm struct {
  142. Name string `binding:"Required"`
  143. }
  144. // Validate valideates the fields
  145. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  146. return validate(errs, ctx.Data, f, ctx.Locale)
  147. }
  148. // TwoFactorAuthForm for logging in with 2FA token.
  149. type TwoFactorAuthForm struct {
  150. Passcode string `binding:"Required"`
  151. }
  152. // Validate validates the fields
  153. func (f *TwoFactorAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  154. return validate(errs, ctx.Data, f, ctx.Locale)
  155. }
  156. // TwoFactorScratchAuthForm for logging in with 2FA scratch token.
  157. type TwoFactorScratchAuthForm struct {
  158. Token string `binding:"Required"`
  159. }
  160. // Validate valideates the fields
  161. func (f *TwoFactorScratchAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  162. return validate(errs, ctx.Data, f, ctx.Locale)
  163. }