user_form.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. Website string `binding:"Url;MaxSize(100)"`
  79. Location string `binding:"MaxSize(50)"`
  80. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  81. }
  82. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  83. return validate(errs, ctx.Data, f, ctx.Locale)
  84. }
  85. type UploadAvatarForm struct {
  86. Enable bool
  87. Avatar *multipart.FileHeader
  88. }
  89. func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  90. return validate(errs, ctx.Data, f, ctx.Locale)
  91. }
  92. type AddEmailForm struct {
  93. Email string `binding:"Required;Email;MaxSize(254)"`
  94. }
  95. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  96. return validate(errs, ctx.Data, f, ctx.Locale)
  97. }
  98. type ChangePasswordForm struct {
  99. OldPassword string `form:"old_password" binding:"Required;MinSize(1);MaxSize(255)"`
  100. Password string `form:"password" binding:"Required;MaxSize(255)"`
  101. Retype string `form:"retype"`
  102. }
  103. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  104. return validate(errs, ctx.Data, f, ctx.Locale)
  105. }
  106. type AddSSHKeyForm struct {
  107. Title string `binding:"Required;MaxSize(50)"`
  108. Content string `binding:"Required"`
  109. }
  110. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  111. return validate(errs, ctx.Data, f, ctx.Locale)
  112. }
  113. type NewAccessTokenForm struct {
  114. Name string `binding:"Required"`
  115. }
  116. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  117. return validate(errs, ctx.Data, f, ctx.Locale)
  118. }