From a2bf16d9d85bcb794f36bb3bbe70e1999668295c Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Wed, 3 Apr 2024 17:55:48 +0200 Subject: [PATCH] Use gravatar --- components/user.templ | 20 ++++++++++++++------ internal/env/env.go | 1 - 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/user.templ b/components/user.templ index b9f8377..c397fb2 100644 --- a/components/user.templ +++ b/components/user.templ @@ -1,12 +1,24 @@ package components import ( - "unicode" + "crypto/md5" + "fmt" + "strings" + "html/template" "github.com/zitadel/oidc/v3/pkg/oidc" openid "github.com/zitadel/zitadel-go/v3/pkg/authentication/oidc" ) +var GravatarTemplate = template.Must(template.New("gravatar").Parse("
")) + +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]) {
{ authCtx.UserInfo.Name }
{ authCtx.UserInfo.Email }
-
-
- { string(unicode.ToUpper(rune(authCtx.UserInfo.Name[0]))) } -
-
+ @templ.FromGoHTML(GravatarTemplate, GetGravatarURL(authCtx.UserInfo.Email, 100))