forked from forgejo/forgejo
Backport #25171 by @silverwind
The plan is that all built-in auth providers use inline SVG for more
flexibility in styling and to get the GitHub icon to follow
`currentcolor`. This only removes the `public/img/auth` directory and
adds the missing svgs to our svg build.
It should map the built-in providers to these SVGs and render them. If
the user has set a Icon URL, it should render that as an `img` tag
instead.
```
gitea-azure-ad
gitea-bitbucket
gitea-discord
gitea-dropbox
gitea-facebook
gitea-gitea
gitea-gitlab
gitea-google
gitea-mastodon
gitea-microsoftonline
gitea-nextcloud
gitea-twitter
gitea-yandex
octicon-mark-github
```
GitHub logo is now white again on dark theme:
<img width="431" alt="Screenshot 2023-06-12 at 21 45 34"
src="27a43504
-d60a-4132-a502-336b25883e4d">
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
c207b94e0c
commit
9cef7a4600
34 changed files with 57 additions and 27 deletions
|
@ -5,6 +5,9 @@ package oauth2
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"net/url"
|
||||
"sort"
|
||||
|
||||
|
@ -19,7 +22,7 @@ import (
|
|||
type Provider interface {
|
||||
Name() string
|
||||
DisplayName() string
|
||||
IconURL() string
|
||||
IconHTML() template.HTML
|
||||
CustomURLSettings() *CustomURLSettings
|
||||
}
|
||||
|
||||
|
@ -35,7 +38,7 @@ type GothProvider interface {
|
|||
}
|
||||
|
||||
// AuthSourceProvider provides a provider for an AuthSource. Multiple auth sources could use the same registered GothProvider
|
||||
// So each auth source should have its own DisplayName and IconURL for display.
|
||||
// So each auth source should have its own DisplayName and IconHTML for display.
|
||||
// The Name is the GothProvider's name, to help to find the GothProvider to sign in.
|
||||
// The DisplayName is the auth source config's name, site admin set it on the admin page, the IconURL can also be set there.
|
||||
type AuthSourceProvider struct {
|
||||
|
@ -51,11 +54,14 @@ func (p *AuthSourceProvider) DisplayName() string {
|
|||
return p.sourceName
|
||||
}
|
||||
|
||||
func (p *AuthSourceProvider) IconURL() string {
|
||||
func (p *AuthSourceProvider) IconHTML() template.HTML {
|
||||
if p.iconURL != "" {
|
||||
return p.iconURL
|
||||
img := fmt.Sprintf(`<img class="gt-mr-3" width="20" height="20" src="%s" alt="%s">`,
|
||||
html.EscapeString(p.iconURL), html.EscapeString(p.DisplayName()),
|
||||
)
|
||||
return template.HTML(img)
|
||||
}
|
||||
return p.GothProvider.IconURL()
|
||||
return p.GothProvider.IconHTML()
|
||||
}
|
||||
|
||||
// Providers contains the map of registered OAuth2 providers in Gitea (based on goth)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue