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.

205 lines
6.5 KiB

Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
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
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
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 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. // InstallForm form for installation page
  11. type InstallForm struct {
  12. DbType string `binding:"Required"`
  13. DbHost string
  14. DbUser string
  15. DbPasswd string
  16. DbName string
  17. SSLMode string
  18. DbPath string
  19. AppName string `binding:"Required" locale:"install.app_name"`
  20. RepoRootPath string `binding:"Required"`
  21. LFSRootPath string
  22. RunUser string `binding:"Required"`
  23. Domain string `binding:"Required"`
  24. SSHPort int
  25. HTTPPort string `binding:"Required"`
  26. AppURL string `binding:"Required"`
  27. LogRootPath string `binding:"Required"`
  28. SMTPHost string
  29. SMTPFrom string
  30. SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
  31. SMTPPasswd string
  32. RegisterConfirm bool
  33. MailNotify bool
  34. OfflineMode bool
  35. DisableGravatar bool
  36. EnableFederatedAvatar bool
  37. DisableRegistration bool
  38. EnableCaptcha bool
  39. RequireSignInView bool
  40. DefaultKeepEmailPrivate bool
  41. NoReplyAddress string
  42. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  43. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  44. AdminConfirmPasswd string
  45. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  46. }
  47. // Validate validates the fields
  48. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  49. return validate(errs, ctx.Data, f, ctx.Locale)
  50. }
  51. // _____ ____ _________________ ___
  52. // / _ \ | | \__ ___/ | \
  53. // / /_\ \| | / | | / ~ \
  54. // / | \ | / | | \ Y /
  55. // \____|__ /______/ |____| \___|_ /
  56. // \/ \/
  57. // RegisterForm form for registering
  58. type RegisterForm struct {
  59. UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
  60. Email string `binding:"Required;Email;MaxSize(254)"`
  61. Password string `binding:"Required;MaxSize(255)"`
  62. Retype string
  63. }
  64. // Validate valideates the fields
  65. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  66. return validate(errs, ctx.Data, f, ctx.Locale)
  67. }
  68. // SignInForm form for signing in with user/password
  69. type SignInForm struct {
  70. UserName string `binding:"Required;MaxSize(254)"`
  71. Password string `binding:"Required;MaxSize(255)"`
  72. Remember bool
  73. }
  74. // Validate valideates the fields
  75. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  76. return validate(errs, ctx.Data, f, ctx.Locale)
  77. }
  78. // __________________________________________.___ _______ ________ _________
  79. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  80. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  81. // / \ | \ | | | | | / | \ \_\ \/ \
  82. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  83. // \/ \/ \/ \/ \/
  84. // UpdateProfileForm form for updating profile
  85. type UpdateProfileForm struct {
  86. Name string `binding:"OmitEmpty;MaxSize(35)"`
  87. FullName string `binding:"MaxSize(100)"`
  88. Email string `binding:"Required;Email;MaxSize(254)"`
  89. KeepEmailPrivate bool
  90. Website string `binding:"Url;MaxSize(255)"`
  91. Location string `binding:"MaxSize(50)"`
  92. }
  93. // Validate validates the fields
  94. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  95. return validate(errs, ctx.Data, f, ctx.Locale)
  96. }
  97. // Avatar types
  98. const (
  99. AvatarLocal string = "local"
  100. AvatarByMail string = "bymail"
  101. )
  102. // AvatarForm form for changing avatar
  103. type AvatarForm struct {
  104. Source string
  105. Avatar *multipart.FileHeader
  106. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  107. Federavatar bool
  108. }
  109. // Validate validates the fields
  110. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  111. return validate(errs, ctx.Data, f, ctx.Locale)
  112. }
  113. // AddEmailForm form for adding new email
  114. type AddEmailForm struct {
  115. Email string `binding:"Required;Email;MaxSize(254)"`
  116. }
  117. // Validate validates the fields
  118. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  119. return validate(errs, ctx.Data, f, ctx.Locale)
  120. }
  121. // ChangePasswordForm form for changing password
  122. type ChangePasswordForm struct {
  123. OldPassword string `form:"old_password" binding:"MaxSize(255)"`
  124. Password string `form:"password" binding:"Required;MaxSize(255)"`
  125. Retype string `form:"retype"`
  126. }
  127. // Validate validates the fields
  128. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  129. return validate(errs, ctx.Data, f, ctx.Locale)
  130. }
  131. // AddOpenIDForm is for changing openid uri
  132. type AddOpenIDForm struct {
  133. Openid string `binding:"Required;MaxSize(256)"`
  134. }
  135. // Validate validates the fields
  136. func (f *AddOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  137. return validate(errs, ctx.Data, f, ctx.Locale)
  138. }
  139. // AddSSHKeyForm form for adding SSH key
  140. type AddSSHKeyForm struct {
  141. Title string `binding:"Required;MaxSize(50)"`
  142. Content string `binding:"Required"`
  143. }
  144. // Validate validates the fields
  145. func (f *AddSSHKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  146. return validate(errs, ctx.Data, f, ctx.Locale)
  147. }
  148. // NewAccessTokenForm form for creating access token
  149. type NewAccessTokenForm struct {
  150. Name string `binding:"Required"`
  151. }
  152. // Validate valideates the fields
  153. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  154. return validate(errs, ctx.Data, f, ctx.Locale)
  155. }
  156. // TwoFactorAuthForm for logging in with 2FA token.
  157. type TwoFactorAuthForm struct {
  158. Passcode string `binding:"Required"`
  159. }
  160. // Validate validates the fields
  161. func (f *TwoFactorAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  162. return validate(errs, ctx.Data, f, ctx.Locale)
  163. }
  164. // TwoFactorScratchAuthForm for logging in with 2FA scratch token.
  165. type TwoFactorScratchAuthForm struct {
  166. Token string `binding:"Required"`
  167. }
  168. // Validate valideates the fields
  169. func (f *TwoFactorScratchAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  170. return validate(errs, ctx.Data, f, ctx.Locale)
  171. }