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 5.5KB

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