2020-06-02 13:28:30 +10:00
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
using System.Threading;
|
2021-02-17 10:11:04 +01:00
|
|
|
using Umbraco.Extensions;
|
2020-06-02 13:28:30 +10:00
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Security
|
|
|
|
|
{
|
|
|
|
|
public static class AuthenticationExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures that the thread culture is set based on the back office user's culture
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void EnsureCulture(this IIdentity identity)
|
2020-08-04 12:54:54 +02:00
|
|
|
{
|
|
|
|
|
var culture = GetCulture(identity);
|
|
|
|
|
if (!(culture is null))
|
|
|
|
|
{
|
|
|
|
|
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static CultureInfo GetCulture(this IIdentity identity)
|
2020-06-02 13:28:30 +10:00
|
|
|
{
|
|
|
|
|
if (identity is UmbracoBackOfficeIdentity umbIdentity && umbIdentity.IsAuthenticated)
|
|
|
|
|
{
|
2021-02-17 10:11:04 +01:00
|
|
|
return CultureInfo.GetCultureInfo(umbIdentity.GetCultureString());
|
2020-06-02 13:28:30 +10:00
|
|
|
}
|
2020-08-04 12:54:54 +02:00
|
|
|
|
|
|
|
|
return null;
|
2020-06-02 13:28:30 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|