user.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. HideEmail bool
  82. Website string `binding:"Url;MaxSize(100)"`
  83. Location string `binding:"MaxSize(50)"`
  84. }
  85. func (f *UpdateProfile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  86. return validate(errs, ctx.Data, f, ctx.Locale)
  87. }
  88. const (
  89. AVATAR_LOCAL string = "local"
  90. AVATAR_BYMAIL string = "bymail"
  91. )
  92. type Avatar struct {
  93. Source string
  94. Avatar *multipart.FileHeader
  95. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  96. Federavatar bool
  97. }
  98. func (f *Avatar) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  99. return validate(errs, ctx.Data, f, ctx.Locale)
  100. }
  101. type AddEmail struct {
  102. Email string `binding:"Required;Email;MaxSize(254)"`
  103. }
  104. func (f *AddEmail) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  105. return validate(errs, ctx.Data, f, ctx.Locale)
  106. }
  107. type ChangePassword struct {
  108. OldPassword string `binding:"Required;MinSize(1);MaxSize(255)"`
  109. Password string `binding:"Required;MaxSize(255)"`
  110. Retype string
  111. }
  112. func (f *ChangePassword) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  113. return validate(errs, ctx.Data, f, ctx.Locale)
  114. }
  115. type AddSSHKey struct {
  116. Title string `binding:"Required;MaxSize(50)"`
  117. Content string `binding:"Required"`
  118. }
  119. func (f *AddSSHKey) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  120. return validate(errs, ctx.Data, f, ctx.Locale)
  121. }
  122. type NewAccessToken struct {
  123. Name string `binding:"Required"`
  124. }
  125. func (f *NewAccessToken) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  126. return validate(errs, ctx.Data, f, ctx.Locale)
  127. }