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.

152 lines
4.8 KiB

Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
8 years ago
  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/go-macaron/binding"
  8. "gopkg.in/macaron.v1"
  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. LogRootPath string `binding:"Required"`
  26. SMTPHost string
  27. SMTPFrom string
  28. SMTPEmail string `binding:"OmitEmpty;Email;MaxSize(254)" locale:"install.mailer_user"`
  29. SMTPPasswd string
  30. RegisterConfirm bool
  31. MailNotify bool
  32. OfflineMode bool
  33. DisableGravatar bool
  34. EnableFederatedAvatar bool
  35. DisableRegistration bool
  36. EnableCaptcha bool
  37. RequireSignInView bool
  38. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  39. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  40. AdminConfirmPasswd string
  41. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  42. }
  43. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  44. return validate(errs, ctx.Data, f, ctx.Locale)
  45. }
  46. // _____ ____ _________________ ___
  47. // / _ \ | | \__ ___/ | \
  48. // / /_\ \| | / | | / ~ \
  49. // / | \ | / | | \ Y /
  50. // \____|__ /______/ |____| \___|_ /
  51. // \/ \/
  52. type RegisterForm struct {
  53. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  54. Email string `binding:"Required;Email;MaxSize(254)"`
  55. Password string `binding:"Required;MaxSize(255)"`
  56. Retype string
  57. }
  58. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  59. return validate(errs, ctx.Data, f, ctx.Locale)
  60. }
  61. type SignInForm struct {
  62. UserName string `binding:"Required;MaxSize(254)"`
  63. Password string `binding:"Required;MaxSize(255)"`
  64. Remember bool
  65. }
  66. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  67. return validate(errs, ctx.Data, f, ctx.Locale)
  68. }
  69. // __________________________________________.___ _______ ________ _________
  70. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  71. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  72. // / \ | \ | | | | | / | \ \_\ \/ \
  73. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  74. // \/ \/ \/ \/ \/
  75. type UpdateProfileForm struct {
  76. Name string `binding:"OmitEmpty;MaxSize(35)"`
  77. FullName string `binding:"MaxSize(100)"`
  78. Email string `binding:"Required;Email;MaxSize(254)"`
  79. Website string `binding:"Url;MaxSize(100)"`
  80. Location string `binding:"MaxSize(50)"`
  81. }
  82. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  83. return validate(errs, ctx.Data, f, ctx.Locale)
  84. }
  85. const (
  86. AvatarLocal string = "local"
  87. AvatarByMail string = "bymail"
  88. )
  89. type AvatarForm struct {
  90. Source string
  91. Avatar *multipart.FileHeader
  92. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  93. Federavatar bool
  94. }
  95. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  96. return validate(errs, ctx.Data, f, ctx.Locale)
  97. }
  98. type AddEmailForm struct {
  99. Email string `binding:"Required;Email;MaxSize(254)"`
  100. }
  101. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  102. return validate(errs, ctx.Data, f, ctx.Locale)
  103. }
  104. type ChangePasswordForm struct {
  105. OldPassword string `form:"old_password" binding:"Required;MinSize(1);MaxSize(255)"`
  106. Password string `form:"password" binding:"Required;MaxSize(255)"`
  107. Retype string `form:"retype"`
  108. }
  109. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  110. return validate(errs, ctx.Data, f, ctx.Locale)
  111. }
  112. type AddSSHKeyForm struct {
  113. Title string `binding:"Required;MaxSize(50)"`
  114. Content string `binding:"Required"`
  115. }
  116. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  117. return validate(errs, ctx.Data, f, ctx.Locale)
  118. }
  119. type NewAccessTokenForm struct {
  120. Name string `binding:"Required"`
  121. }
  122. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  123. return validate(errs, ctx.Data, f, ctx.Locale)
  124. }