gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package oauth2
  4. import (
  5. "html/template"
  6. "code.gitea.io/gitea/modules/log"
  7. "code.gitea.io/gitea/modules/svg"
  8. )
  9. // BaseProvider represents a common base for Provider
  10. type BaseProvider struct {
  11. name string
  12. displayName string
  13. // TODO: maybe some providers also support SSH public keys, then they can set this to true
  14. supportSSHPublicKey bool
  15. }
  16. func (b *BaseProvider) SupportSSHPublicKey() bool {
  17. return b.supportSSHPublicKey
  18. }
  19. // Name provides the technical name for this provider
  20. func (b *BaseProvider) Name() string {
  21. return b.name
  22. }
  23. // DisplayName returns the friendly name for this provider
  24. func (b *BaseProvider) DisplayName() string {
  25. return b.displayName
  26. }
  27. // IconHTML returns icon HTML for this provider
  28. func (b *BaseProvider) IconHTML(size int) template.HTML {
  29. svgName := "gitea-" + b.name
  30. switch b.name {
  31. case "gplus":
  32. svgName = "gitea-google"
  33. case "github":
  34. svgName = "octicon-mark-github"
  35. }
  36. svgHTML := svg.RenderHTML(svgName, size, "tw-mr-2")
  37. if svgHTML == "" {
  38. log.Error("No SVG icon for oauth2 provider %q", b.name)
  39. svgHTML = svg.RenderHTML("gitea-openid", size, "tw-mr-2")
  40. }
  41. return svgHTML
  42. }
  43. // CustomURLSettings returns the custom url settings for this provider
  44. func (b *BaseProvider) CustomURLSettings() *CustomURLSettings {
  45. return nil
  46. }
  47. var _ Provider = &BaseProvider{}