user_form.go 4.8 KB

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