user_form.go 4.9 KB

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