user_form.go 4.7 KB

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