user.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 form
  5. import (
  6. "mime/multipart"
  7. "github.com/go-macaron/binding"
  8. "gopkg.in/macaron.v1"
  9. )
  10. type Install 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. UseBuiltinSSHServer bool
  24. HTTPPort string `binding:"Required"`
  25. AppUrl string `binding:"Required"`
  26. LogRootPath string `binding:"Required"`
  27. EnableConsoleMode bool
  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. 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. func (f *Install) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  46. return validate(errs, ctx.Data, f, ctx.Locale)
  47. }
  48. // _____ ____ _________________ ___
  49. // / _ \ | | \__ ___/ | \
  50. // / /_\ \| | / | | / ~ \
  51. // / | \ | / | | \ Y /
  52. // \____|__ /______/ |____| \___|_ /
  53. // \/ \/
  54. type Register struct {
  55. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  56. Email string `binding:"Required;Email;MaxSize(254)"`
  57. Password string `binding:"Required;MaxSize(255)"`
  58. Retype string
  59. }
  60. func (f *Register) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  61. return validate(errs, ctx.Data, f, ctx.Locale)
  62. }
  63. type SignIn struct {
  64. UserName string `binding:"Required;MaxSize(254)"`
  65. Password string `binding:"Required;MaxSize(255)"`
  66. Remember bool
  67. }
  68. func (f *SignIn) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  69. return validate(errs, ctx.Data, f, ctx.Locale)
  70. }
  71. // __________________________________________.___ _______ ________ _________
  72. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  73. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  74. // / \ | \ | | | | | / | \ \_\ \/ \
  75. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  76. // \/ \/ \/ \/ \/
  77. type UpdateProfile struct {
  78. Name string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  79. FullName string `binding:"MaxSize(100)"`
  80. Email string `binding:"Required;Email;MaxSize(254)"`
  81. Website string `binding:"Url;MaxSize(100)"`
  82. Location string `binding:"MaxSize(50)"`
  83. }
  84. func (f *UpdateProfile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  85. return validate(errs, ctx.Data, f, ctx.Locale)
  86. }
  87. const (
  88. AVATAR_LOCAL string = "local"
  89. AVATAR_BYMAIL string = "bymail"
  90. )
  91. type Avatar struct {
  92. Source string
  93. Avatar *multipart.FileHeader
  94. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  95. Federavatar bool
  96. }
  97. func (f *Avatar) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  98. return validate(errs, ctx.Data, f, ctx.Locale)
  99. }
  100. type AddEmail struct {
  101. Email string `binding:"Required;Email;MaxSize(254)"`
  102. }
  103. func (f *AddEmail) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  104. return validate(errs, ctx.Data, f, ctx.Locale)
  105. }
  106. type ChangePassword struct {
  107. OldPassword string `binding:"Required;MinSize(1);MaxSize(255)"`
  108. Password string `binding:"Required;MaxSize(255)"`
  109. Retype string
  110. }
  111. func (f *ChangePassword) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  112. return validate(errs, ctx.Data, f, ctx.Locale)
  113. }
  114. type AddSSHKey struct {
  115. Title string `binding:"Required;MaxSize(50)"`
  116. Content string `binding:"Required"`
  117. }
  118. func (f *AddSSHKey) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  119. return validate(errs, ctx.Data, f, ctx.Locale)
  120. }
  121. type NewAccessToken struct {
  122. Name string `binding:"Required"`
  123. }
  124. func (f *NewAccessToken) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  125. return validate(errs, ctx.Data, f, ctx.Locale)
  126. }