user_form.go 4.8 KB

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