You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.9 KiB

  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/Unknwon/macaron"
  8. "github.com/macaron-contrib/binding"
  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. SMTPHost string
  26. SMTPFrom string
  27. SMTPEmail string `binding:"OmitEmpty;Email;MaxSize(50)" locale:"install.mailer_user"`
  28. SMTPPasswd string
  29. RegisterConfirm bool
  30. MailNotify bool
  31. OfflineMode bool
  32. DisableRegistration bool
  33. RequireSignInView bool
  34. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  35. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  36. AdminConfirmPasswd string
  37. AdminEmail string `binding:"OmitEmpty;Email;MaxSize(50)" locale:"install.admin_email"`
  38. }
  39. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  40. return validate(errs, ctx.Data, f, ctx.Locale)
  41. }
  42. // _____ ____ _________________ ___
  43. // / _ \ | | \__ ___/ | \
  44. // / /_\ \| | / | | / ~ \
  45. // / | \ | / | | \ Y /
  46. // \____|__ /______/ |____| \___|_ /
  47. // \/ \/
  48. type RegisterForm struct {
  49. UserName string `form:"uname" binding:"Required;AlphaDashDot;MaxSize(35)"`
  50. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  51. Password string `form:"password" binding:"Required;MaxSize(255)"`
  52. Retype string `form:"retype"`
  53. LoginType string `form:"logintype"`
  54. LoginName string `form:"loginname"`
  55. }
  56. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  57. return validate(errs, ctx.Data, f, ctx.Locale)
  58. }
  59. type SignInForm struct {
  60. UserName string `form:"uname" binding:"Required;MaxSize(35)"`
  61. Password string `form:"password" binding:"Required;MaxSize(255)"`
  62. Remember bool `form:"remember"`
  63. }
  64. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  65. return validate(errs, ctx.Data, f, ctx.Locale)
  66. }
  67. // __________________________________________.___ _______ ________ _________
  68. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  69. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  70. // / \ | \ | | | | | / | \ \_\ \/ \
  71. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  72. // \/ \/ \/ \/ \/
  73. type UpdateProfileForm struct {
  74. UserName string `form:"uname" binding:"Required;MaxSize(35)"`
  75. FullName string `form:"fullname" binding:"MaxSize(100)"`
  76. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  77. Website string `form:"website" binding:"Url;MaxSize(100)"`
  78. Location string `form:"location" binding:"MaxSize(50)"`
  79. Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
  80. }
  81. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  82. return validate(errs, ctx.Data, f, ctx.Locale)
  83. }
  84. type UploadAvatarForm struct {
  85. Enable bool `form:"enable"`
  86. Avatar *multipart.FileHeader `form:"avatar"`
  87. }
  88. func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  89. return validate(errs, ctx.Data, f, ctx.Locale)
  90. }
  91. type AddEmailForm struct {
  92. Email string `binding:"Required;Email;MaxSize(50)"`
  93. }
  94. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  95. return validate(errs, ctx.Data, f, ctx.Locale)
  96. }
  97. type ChangePasswordForm struct {
  98. OldPassword string `form:"old_password" binding:"Required;MinSize(1);MaxSize(255)"`
  99. Password string `form:"password" binding:"Required;MaxSize(255)"`
  100. Retype string `form:"retype"`
  101. }
  102. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  103. return validate(errs, ctx.Data, f, ctx.Locale)
  104. }
  105. type AddSSHKeyForm struct {
  106. Title string `binding:"Required;MaxSize(50)"`
  107. Content string `binding:"Required"`
  108. }
  109. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  110. return validate(errs, ctx.Data, f, ctx.Locale)
  111. }
  112. type NewAccessTokenForm struct {
  113. Name string `binding:"Required"`
  114. }
  115. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  116. return validate(errs, ctx.Data, f, ctx.Locale)
  117. }