29 lines
1,020 B
Text
29 lines
1,020 B
Text
package components
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"strings"
|
|
"html/template"
|
|
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
|
)
|
|
|
|
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>"))
|
|
|
|
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(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>
|
|
@templ.FromGoHTML(GravatarTemplate, GetGravatarURL(claims.Email, 100))
|
|
</div>
|
|
}
|