user_form.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. Website string `form:"website" binding:"Url;MaxSize(100)"`
  72. Location string `form:"location" binding:"MaxSize(50)"`
  73. Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
  74. }
  75. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  76. return validate(errs, ctx.Data, f, ctx.Locale)
  77. }
  78. type UploadAvatarForm struct {
  79. Enable bool `form:"enable"`
  80. Avatar *multipart.FileHeader `form:"avatar"`
  81. }
  82. func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  83. return validate(errs, ctx.Data, f, ctx.Locale)
  84. }
  85. type AddEmailForm struct {
  86. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  87. }
  88. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  89. return validate(errs, ctx.Data, f, ctx.Locale)
  90. }
  91. type ChangePasswordForm struct {
  92. OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"`
  93. Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
  94. Retype string `form:"retype"`
  95. }
  96. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  97. return validate(errs, ctx.Data, f, ctx.Locale)
  98. }
  99. type AddSSHKeyForm struct {
  100. SSHTitle string `form:"title" binding:"Required"`
  101. Content string `form:"content" binding:"Required"`
  102. }
  103. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  104. return validate(errs, ctx.Data, f, ctx.Locale)
  105. }
  106. type NewAccessTokenForm struct {
  107. Name string `form:"name" binding:"Required"`
  108. }
  109. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  110. return validate(errs, ctx.Data, f, ctx.Locale)
  111. }