mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.4 KiB
72 lines
2.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Shared.Identity;
|
|
using Squidex.Shared.Users;
|
|
|
|
namespace Squidex.Domain.Users
|
|
{
|
|
public static class UserExtensions
|
|
{
|
|
public static void SetDisplayName(this IUser user, string displayName)
|
|
{
|
|
user.SetClaim(SquidexClaimTypes.SquidexDisplayName, displayName);
|
|
}
|
|
|
|
public static void SetPictureUrl(this IUser user, string pictureUrl)
|
|
{
|
|
user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, pictureUrl);
|
|
}
|
|
|
|
public static void SetPictureUrlToStore(this IUser user)
|
|
{
|
|
user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, "store");
|
|
}
|
|
|
|
public static void SetPictureUrlFromGravatar(this IUser user, string email)
|
|
{
|
|
user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, GravatarHelper.CreatePictureUrl(email));
|
|
}
|
|
|
|
public static bool IsPictureUrlStored(this IUser user)
|
|
{
|
|
return string.Equals(user.Claims.FirstOrDefault(x => x.Type == SquidexClaimTypes.SquidexPictureUrl)?.Value, "store", StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public static string PictureUrl(this IUser user)
|
|
{
|
|
return user.Claims.FirstOrDefault(x => x.Type == SquidexClaimTypes.SquidexPictureUrl)?.Value;
|
|
}
|
|
|
|
public static string DisplayName(this IUser user)
|
|
{
|
|
return user.Claims.FirstOrDefault(x => x.Type == SquidexClaimTypes.SquidexDisplayName)?.Value;
|
|
}
|
|
|
|
public static string PictureNormalizedUrl(this IUser user)
|
|
{
|
|
var url = user.Claims.FirstOrDefault(x => x.Type == SquidexClaimTypes.SquidexPictureUrl)?.Value;
|
|
|
|
if (!string.IsNullOrWhiteSpace(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute) && url.Contains("gravatar"))
|
|
{
|
|
if (url.Contains("?"))
|
|
{
|
|
url += "&d=404";
|
|
}
|
|
else
|
|
{
|
|
url += "?d=404";
|
|
}
|
|
}
|
|
|
|
return url;
|
|
}
|
|
}
|
|
}
|
|
|