user.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. DbSchema string
  17. SSLMode string
  18. DbPath string
  19. AppName string `binding:"Required" locale:"install.app_name"`
  20. RepoRootPath string `binding:"Required"`
  21. RunUser string `binding:"Required"`
  22. Domain string `binding:"Required"`
  23. SSHPort int
  24. UseBuiltinSSHServer bool
  25. HTTPPort string `binding:"Required"`
  26. AppUrl string `binding:"Required"`
  27. LogRootPath string `binding:"Required"`
  28. EnableConsoleMode bool
  29. DefaultBranch string
  30. SMTPHost string
  31. SMTPFrom string
  32. SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
  33. SMTPPasswd string
  34. RegisterConfirm bool
  35. MailNotify bool
  36. OfflineMode bool
  37. DisableGravatar bool
  38. EnableFederatedAvatar bool
  39. DisableRegistration bool
  40. EnableCaptcha bool
  41. RequireSignInView bool
  42. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  43. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  44. AdminConfirmPasswd string
  45. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  46. }
  47. func (f *Install) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  48. return validate(errs, ctx.Data, f, ctx.Locale)
  49. }
  50. // _____ ____ _________________ ___
  51. // / _ \ | | \__ ___/ | \
  52. // / /_\ \| | / | | / ~ \
  53. // / | \ | / | | \ Y /
  54. // \____|__ /______/ |____| \___|_ /
  55. // \/ \/
  56. type Register struct {
  57. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  58. Email string `binding:"Required;Email;MaxSize(254)"`
  59. Password string `binding:"Required;MaxSize(255)"`
  60. Retype string
  61. }
  62. func (f *Register) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  63. return validate(errs, ctx.Data, f, ctx.Locale)
  64. }
  65. type SignIn struct {
  66. UserName string `binding:"Required;MaxSize(254)"`
  67. Password string `binding:"Required;MaxSize(255)"`
  68. LoginSource int64
  69. Remember bool
  70. }
  71. func (f *SignIn) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  72. return validate(errs, ctx.Data, f, ctx.Locale)
  73. }
  74. // __________________________________________.___ _______ ________ _________
  75. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  76. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  77. // / \ | \ | | | | | / | \ \_\ \/ \
  78. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  79. // \/ \/ \/ \/ \/
  80. type UpdateProfile struct {
  81. Name string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  82. FullName string `binding:"MaxSize(100)"`
  83. Website string `binding:"Url;MaxSize(100)"`
  84. Location string `binding:"MaxSize(50)"`
  85. }
  86. func (f *UpdateProfile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  87. return validate(errs, ctx.Data, f, ctx.Locale)
  88. }
  89. const (
  90. AvatarLocal string = "local"
  91. AvatarLookup string = "lookup"
  92. )
  93. type Avatar struct {
  94. Source string
  95. Avatar *multipart.FileHeader
  96. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  97. Federavatar bool
  98. }
  99. func (f *Avatar) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  100. return validate(errs, ctx.Data, f, ctx.Locale)
  101. }
  102. type AddEmail struct {
  103. Email string `binding:"Required;Email;MaxSize(254)"`
  104. }
  105. func (f *AddEmail) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  106. return validate(errs, ctx.Data, f, ctx.Locale)
  107. }
  108. type ChangePassword struct {
  109. OldPassword string `binding:"Required;MinSize(1);MaxSize(255)"`
  110. Password string `binding:"Required;MaxSize(255)"`
  111. Retype string
  112. }
  113. func (f *ChangePassword) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  114. return validate(errs, ctx.Data, f, ctx.Locale)
  115. }
  116. type AddSSHKey struct {
  117. Title string `binding:"Required;MaxSize(50)"`
  118. Content string `binding:"Required"`
  119. }
  120. func (f *AddSSHKey) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  121. return validate(errs, ctx.Data, f, ctx.Locale)
  122. }
  123. type NewAccessToken struct {
  124. Name string `binding:"Required"`
  125. }
  126. func (f *NewAccessToken) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  127. return validate(errs, ctx.Data, f, ctx.Locale)
  128. }