user.go 4.8 KB

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