Use gravatar
This commit is contained in:
parent
19456eadd8
commit
a2bf16d9d8
2 changed files with 14 additions and 7 deletions
|
@ -1,12 +1,24 @@
|
||||||
package components
|
package components
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unicode"
|
"crypto/md5"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
"github.com/zitadel/oidc/v3/pkg/oidc"
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
||||||
openid "github.com/zitadel/zitadel-go/v3/pkg/authentication/oidc"
|
openid "github.com/zitadel/zitadel-go/v3/pkg/authentication/oidc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var GravatarTemplate = template.Must(template.New("gravatar").Parse("<div class=\"avatar rounded w-10 h-10 bg-contain bg-center bg-origin-content bg-no-repeat opacity-90\" style=\"background-image: url({{ . }})\"></div>"))
|
||||||
|
|
||||||
|
func GetGravatarURL(email string, size uint) string {
|
||||||
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
hash := md5.Sum([]byte(email))
|
||||||
|
gravatarURL := fmt.Sprintf("https://www.gravatar.com/avatar/%x?s=%d", hash, size)
|
||||||
|
return string(templ.URL(gravatarURL))
|
||||||
|
}
|
||||||
|
|
||||||
templ User(authCtx *openid.UserInfoContext[*oidc.IDTokenClaims, *oidc.UserInfo]) {
|
templ User(authCtx *openid.UserInfoContext[*oidc.IDTokenClaims, *oidc.UserInfo]) {
|
||||||
<div
|
<div
|
||||||
x-data="{
|
x-data="{
|
||||||
|
@ -27,11 +39,7 @@ templ User(authCtx *openid.UserInfoContext[*oidc.IDTokenClaims, *oidc.UserInfo])
|
||||||
<div class="text-secondary text-sm font-bold whitespace-nowrap">{ authCtx.UserInfo.Name }</div>
|
<div class="text-secondary text-sm font-bold whitespace-nowrap">{ authCtx.UserInfo.Name }</div>
|
||||||
<div class="text-gray-500 text-xs whitespace-nowrap">{ authCtx.UserInfo.Email }</div>
|
<div class="text-gray-500 text-xs whitespace-nowrap">{ authCtx.UserInfo.Email }</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="avatar">
|
@templ.FromGoHTML(GravatarTemplate, GetGravatarURL(authCtx.UserInfo.Email, 100))
|
||||||
<div class="w-10 h-10 rounded-xl bg-secondary relative">
|
|
||||||
<span class="font-xl text-secondary-content absolute top-1/2 left-1/2 -translate-y-1/2 -translate-x-1/2">{ string(unicode.ToUpper(rune(authCtx.UserInfo.Name[0]))) }</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<ul
|
<ul
|
||||||
x-show="open"
|
x-show="open"
|
||||||
|
|
1
internal/env/env.go
vendored
1
internal/env/env.go
vendored
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"`
|
TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"`
|
||||||
PublicUrl string `env:"PUBLIC_URL" validate:"url"`
|
|
||||||
Title string `env:"TITLE" envDefault:"goDash"`
|
Title string `env:"TITLE" envDefault:"goDash"`
|
||||||
Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"`
|
Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"`
|
||||||
Version string `env:"APP_VERSION"`
|
Version string `env:"APP_VERSION"`
|
||||||
|
|
Loading…
Reference in a new issue