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.

user_form.go 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. AllowOnlyExternalRegistration bool
  41. EnableCaptcha bool
  42. RequireSignInView bool
  43. DefaultKeepEmailPrivate bool
  44. DefaultAllowCreateOrganization bool
  45. DefaultEnableTimetracking bool
  46. NoReplyAddress string
  47. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  48. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  49. AdminConfirmPasswd string
  50. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  51. }
  52. // Validate validates the fields
  53. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  54. return validate(errs, ctx.Data, f, ctx.Locale)
  55. }
  56. // _____ ____ _________________ ___
  57. // / _ \ | | \__ ___/ | \
  58. // / /_\ \| | / | | / ~ \
  59. // / | \ | / | | \ Y /
  60. // \____|__ /______/ |____| \___|_ /
  61. // \/ \/
  62. // RegisterForm form for registering
  63. type RegisterForm struct {
  64. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  65. Email string `binding:"Required;Email;MaxSize(254)"`
  66. Password string `binding:"Required;MaxSize(255)"`
  67. Retype string
  68. GRecaptchaResponse string `form:"g-recaptcha-response"`
  69. }
  70. // Validate valideates the fields
  71. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  72. return validate(errs, ctx.Data, f, ctx.Locale)
  73. }
  74. // MustChangePasswordForm form for updating your password after account creation
  75. // by an admin
  76. type MustChangePasswordForm struct {
  77. Password string `binding:"Required;MaxSize(255)"`
  78. Retype string
  79. }
  80. // Validate valideates the fields
  81. func (f *MustChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  82. return validate(errs, ctx.Data, f, ctx.Locale)
  83. }
  84. // SignInForm form for signing in with user/password
  85. type SignInForm struct {
  86. UserName string `binding:"Required;MaxSize(254)"`
  87. Password string `binding:"Required;MaxSize(255)"`
  88. Remember bool
  89. }
  90. // Validate valideates the fields
  91. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  92. return validate(errs, ctx.Data, f, ctx.Locale)
  93. }
  94. // __________________________________________.___ _______ ________ _________
  95. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  96. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  97. // / \ | \ | | | | | / | \ \_\ \/ \
  98. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  99. // \/ \/ \/ \/ \/
  100. // UpdateProfileForm form for updating profile
  101. type UpdateProfileForm struct {
  102. Name string `binding:"AlphaDashDot;MaxSize(35)"`
  103. FullName string `binding:"MaxSize(100)"`
  104. Email string `binding:"Required;Email;MaxSize(254)"`
  105. KeepEmailPrivate bool
  106. Website string `binding:"ValidUrl;MaxSize(255)"`
  107. Location string `binding:"MaxSize(50)"`
  108. Language string `binding:"Size(5)"`
  109. }
  110. // Validate validates the fields
  111. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  112. return validate(errs, ctx.Data, f, ctx.Locale)
  113. }
  114. // Avatar types
  115. const (
  116. AvatarLocal string = "local"
  117. AvatarByMail string = "bymail"
  118. )
  119. // AvatarForm form for changing avatar
  120. type AvatarForm struct {
  121. Source string
  122. Avatar *multipart.FileHeader
  123. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  124. Federavatar bool
  125. }
  126. // Validate validates the fields
  127. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  128. return validate(errs, ctx.Data, f, ctx.Locale)
  129. }
  130. // AddEmailForm form for adding new email
  131. type AddEmailForm struct {
  132. Email string `binding:"Required;Email;MaxSize(254)"`
  133. }
  134. // Validate validates the fields
  135. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  136. return validate(errs, ctx.Data, f, ctx.Locale)
  137. }
  138. // ChangePasswordForm form for changing password
  139. type ChangePasswordForm struct {
  140. OldPassword string `form:"old_password" binding:"MaxSize(255)"`
  141. Password string `form:"password" binding:"Required;MaxSize(255)"`
  142. Retype string `form:"retype"`
  143. }
  144. // Validate validates the fields
  145. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  146. return validate(errs, ctx.Data, f, ctx.Locale)
  147. }
  148. // AddOpenIDForm is for changing openid uri
  149. type AddOpenIDForm struct {
  150. Openid string `binding:"Required;MaxSize(256)"`
  151. }
  152. // Validate validates the fields
  153. func (f *AddOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  154. return validate(errs, ctx.Data, f, ctx.Locale)
  155. }
  156. // AddKeyForm form for adding SSH/GPG key
  157. type AddKeyForm struct {
  158. Type string `binding:"OmitEmpty"`
  159. Title string `binding:"Required;MaxSize(50)"`
  160. Content string `binding:"Required"`
  161. IsWritable bool
  162. }
  163. // Validate validates the fields
  164. func (f *AddKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  165. return validate(errs, ctx.Data, f, ctx.Locale)
  166. }
  167. // NewAccessTokenForm form for creating access token
  168. type NewAccessTokenForm struct {
  169. Name string `binding:"Required;MaxSize(255)"`
  170. }
  171. // Validate valideates the fields
  172. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  173. return validate(errs, ctx.Data, f, ctx.Locale)
  174. }
  175. // TwoFactorAuthForm for logging in with 2FA token.
  176. type TwoFactorAuthForm struct {
  177. Passcode string `binding:"Required"`
  178. }
  179. // Validate validates the fields
  180. func (f *TwoFactorAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  181. return validate(errs, ctx.Data, f, ctx.Locale)
  182. }
  183. // TwoFactorScratchAuthForm for logging in with 2FA scratch token.
  184. type TwoFactorScratchAuthForm struct {
  185. Token string `binding:"Required"`
  186. }
  187. // Validate valideates the fields
  188. func (f *TwoFactorScratchAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  189. return validate(errs, ctx.Data, f, ctx.Locale)
  190. }
  191. // U2FRegistrationForm for reserving an U2F name
  192. type U2FRegistrationForm struct {
  193. Name string `binding:"Required"`
  194. }
  195. // Validate valideates the fields
  196. func (f *U2FRegistrationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  197. return validate(errs, ctx.Data, f, ctx.Locale)
  198. }
  199. // U2FDeleteForm for deleting U2F keys
  200. type U2FDeleteForm struct {
  201. ID int64 `binding:"Required"`
  202. }
  203. // Validate valideates the fields
  204. func (f *U2FDeleteForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  205. return validate(errs, ctx.Data, f, ctx.Locale)
  206. }