user_form.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. "github.com/Unknwon/macaron"
  7. "github.com/macaron-contrib/binding"
  8. )
  9. type InstallForm struct {
  10. Database string `form:"database" binding:"Required"`
  11. DbHost string `form:"host"`
  12. DbUser string `form:"user"`
  13. DbPasswd string `form:"passwd"`
  14. DatabaseName string `form:"database_name"`
  15. SslMode string `form:"ssl_mode"`
  16. DatabasePath string `form:"database_path"`
  17. RepoRootPath string `form:"repo_path" binding:"Required"`
  18. RunUser string `form:"run_user" binding:"Required"`
  19. Domain string `form:"domain" binding:"Required"`
  20. AppUrl string `form:"app_url" binding:"Required"`
  21. SmtpHost string `form:"smtp_host"`
  22. SmtpEmail string `form:"mailer_user"`
  23. SmtpPasswd string `form:"mailer_pwd"`
  24. RegisterConfirm string `form:"register_confirm"`
  25. MailNotify string `form:"mail_notify"`
  26. AdminName string `form:"admin_name" binding:"Required;AlphaDashDot;MaxSize(30)"`
  27. AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(255)"`
  28. ConfirmPasswd string `form:"confirm_passwd" binding:"Required;MinSize(6);MaxSize(255)"`
  29. AdminEmail string `form:"admin_email" binding:"Required;Email;MaxSize(50)"`
  30. }
  31. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  32. return validate(errs, ctx.Data, f, ctx.Locale)
  33. }
  34. // _____ ____ _________________ ___
  35. // / _ \ | | \__ ___/ | \
  36. // / /_\ \| | / | | / ~ \
  37. // / | \ | / | | \ Y /
  38. // \____|__ /______/ |____| \___|_ /
  39. // \/ \/
  40. type RegisterForm struct {
  41. UserName string `form:"uname" binding:"Required;AlphaDashDot;MaxSize(35)"`
  42. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  43. Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
  44. Retype string `form:"retype"`
  45. LoginType string `form:"logintype"`
  46. LoginName string `form:"loginname"`
  47. }
  48. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  49. return validate(errs, ctx.Data, f, ctx.Locale)
  50. }
  51. type SignInForm struct {
  52. UserName string `form:"uname" binding:"Required;MaxSize(35)"`
  53. Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
  54. Remember bool `form:"remember"`
  55. }
  56. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  57. return validate(errs, ctx.Data, f, ctx.Locale)
  58. }
  59. // __________________________________________.___ _______ ________ _________
  60. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  61. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  62. // / \ | \ | | | | | / | \ \_\ \/ \
  63. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  64. // \/ \/ \/ \/ \/
  65. type UpdateProfileForm struct {
  66. UserName string `form:"uname" binding:"Required;MaxSize(35)"`
  67. FullName string `form:"fullname" binding:"MaxSize(100)"`
  68. Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
  69. Website string `form:"website" binding:"Url;MaxSize(100)"`
  70. Location string `form:"location" binding:"MaxSize(50)"`
  71. Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
  72. }
  73. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  74. return validate(errs, ctx.Data, f, ctx.Locale)
  75. }
  76. type ChangePasswordForm struct {
  77. OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"`
  78. Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
  79. Retype string `form:"retype"`
  80. }
  81. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  82. return validate(errs, ctx.Data, f, ctx.Locale)
  83. }
  84. type AddSSHKeyForm struct {
  85. SSHTitle string `form:"title" binding:"Required"`
  86. Content string `form:"content" binding:"Required"`
  87. }
  88. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  89. return validate(errs, ctx.Data, f, ctx.Locale)
  90. }
  91. type NewAccessTokenForm struct {
  92. Name string `form:"name" binding:"Required"`
  93. }
  94. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  95. return validate(errs, ctx.Data, f, ctx.Locale)
  96. }