godash/components/user.templ

30 lines
1,020 B
Text
Raw Normal View History

2024-03-25 20:31:51 +01:00
package components
import (
2024-04-03 17:55:48 +02:00
"crypto/md5"
"fmt"
"strings"
"html/template"
2024-04-12 16:19:11 +02:00
"github.com/zitadel/oidc/v3/pkg/oidc"
2024-03-25 20:31:51 +01:00
)
2024-04-11 14:53:52 +02:00
var GravatarTemplate = template.Must(template.New("gravatar").Parse("<div class=\"relative avatar rounded w-10 h-10 bg-contain bg-center bg-origin-content bg-no-repeat opacity-90\" style=\"background-image: url({{ . }})\"></div>"))
2024-04-03 17:55:48 +02:00
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))
}
2024-04-12 16:19:11 +02:00
templ User(claims *oidc.UserInfo) {
<div class="flex items-center gap-2 transition-opacity">
<div class="hidden md:flex flex-col items-end">
<div class="text-secondary text-sm font-bold whitespace-nowrap">{ claims.Name }</div>
<div class="text-gray-500 text-xs whitespace-nowrap">{ claims.Email }</div>
</div>
2024-04-12 16:19:11 +02:00
@templ.FromGoHTML(GravatarTemplate, GetGravatarURL(claims.Email, 100))
</div>
2024-03-25 20:31:51 +01:00
}