It builds!

This commit is contained in:
Shannon
2020-10-23 14:18:53 +11:00
parent 1400a02798
commit 64d8b56eca
80 changed files with 601 additions and 2356 deletions

View File

@@ -1,7 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Semver;
using Umbraco.Core;
using Umbraco.Core.Security;
using Umbraco.Core.Serialization;
namespace Umbraco.Extensions
{
@@ -21,6 +26,49 @@ namespace Umbraco.Extensions
return true;
}
/// <summary>
/// Copies data from a request cookie to view data and then clears the cookie in the response
/// </summary>
/// <param name="viewData"></param>
/// <param name="httpContext"></param>
/// <param name="cookieName"></param>
/// <returns></returns>
/// <remarks>
/// <para>
/// This is similar to TempData but in some cases we cannot use TempData which relies on the temp data provider and session.
/// The cookie value can either be a simple string value
/// </para>
/// </remarks>
public static bool FromBase64CookieData<T>(this ViewDataDictionary viewData, HttpContext httpContext, string cookieName, IJsonSerializer serializer)
{
var hasCookie = httpContext.Request.Cookies.ContainsKey(cookieName);
if (!hasCookie) return false;
// get the cookie value
if (!httpContext.Request.Cookies.TryGetValue(cookieName, out var cookieVal))
{
return false;
}
// ensure the cookie is expired (must be done after reading the value)
httpContext.Response.Cookies.Delete(cookieName);
if (cookieVal.IsNullOrWhiteSpace())
return false;
try
{
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(System.Net.WebUtility.UrlDecode(cookieVal)));
// deserialize to T and store in viewdata
viewData[cookieName] = serializer.Deserialize<T>(decoded);
return true;
}
catch (Exception)
{
return false;
}
}
public static string GetUmbracoPath(this ViewDataDictionary viewData)
{
return (string)viewData[TokenUmbracoPath];
@@ -60,14 +108,24 @@ namespace Umbraco.Extensions
return (SemVersion) viewData[TokenUmbracoVersion];
}
public static IEnumerable<string> GetExternalSignInError(this ViewDataDictionary viewData)
/// <summary>
/// Used by the back office login screen to get any registered external login provider errors
/// </summary>
/// <param name="viewData"></param>
/// <returns></returns>
public static BackOfficeExternalLoginProviderErrors GetExternalSignInProviderErrors(this ViewDataDictionary viewData)
{
return (IEnumerable<string>)viewData[TokenExternalSignInError];
return (BackOfficeExternalLoginProviderErrors)viewData[TokenExternalSignInError];
}
public static void SetExternalSignInError(this ViewDataDictionary viewData, IEnumerable<string> value)
/// <summary>
/// Used by the back office controller to register any external login provider errors
/// </summary>
/// <param name="viewData"></param>
/// <param name="errors"></param>
public static void SetExternalSignInProviderErrors(this ViewDataDictionary viewData, BackOfficeExternalLoginProviderErrors errors)
{
viewData[TokenExternalSignInError] = value;
viewData[TokenExternalSignInError] = errors;
}
public static string GetPasswordResetCode(this ViewDataDictionary viewData)