65 lines
2.9 KiB
C#
65 lines
2.9 KiB
C#
using EnvelopeGenerator.Web.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers
|
|
{
|
|
public static class ControllerBaseExtensions
|
|
{
|
|
public static string? GetClaimValue(this ControllerBase controller, string claimType) => controller.User.FindFirstValue(claimType);
|
|
|
|
public static string? GetAuthEnvelopeUuid(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
|
|
public static string? GetAuthReceiverSignature(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Hash);
|
|
|
|
public static string? GetAuthReceiverName(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Name);
|
|
|
|
public static string? GetAuthReceiverMail(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Email);
|
|
|
|
public static string? GetAuthEnvelopeTitle(this ControllerBase controller) => controller.User.FindFirstValue(EnvelopeClaimTypes.Title);
|
|
|
|
public static int? GetAuthEnvelopeId(this ControllerBase controller)
|
|
{
|
|
var env_id_str = controller.User.FindFirstValue(EnvelopeClaimTypes.Id);
|
|
return int.TryParse(env_id_str, out int env_id) ? env_id : null;
|
|
}
|
|
|
|
//TODO: integrate localizer for ready-to-use views
|
|
public static ViewResult ViewError(this Controller controller, ErrorViewModel errorViewModel) => controller.View("_Error", errorViewModel);
|
|
|
|
public static ViewResult ViewError404(this Controller controller) => controller.ViewError(new()
|
|
{
|
|
Title = "404",
|
|
Subtitle = "Die von Ihnen gesuchte Seite ist nicht verfügbar",
|
|
Body = "Sie können derzeit nur an Sie gerichtete Briefe einsehen und unterschreiben.",
|
|
});
|
|
|
|
public static ViewResult ViewEnvelopeNotFound(this Controller controller) => controller.ViewError(new()
|
|
{
|
|
Title = "404",
|
|
Subtitle = "Document not found",
|
|
Body = "Wenn Sie diese URL in Ihrer E-Mail erhalten haben, wenden Sie sich bitte an das IT-Team."
|
|
});
|
|
|
|
public static ViewResult ViewDocumentNotFound(this Controller controller) => controller.ViewError(new()
|
|
{
|
|
Title = "404",
|
|
Subtitle = "Umschlag nicht gefunden",
|
|
Body = "Wenn Sie diese URL in Ihrer E-Mail erhalten haben, wenden Sie sich bitte an das IT-Team."
|
|
});
|
|
|
|
public static ViewResult ViewAccessCodeNotSent(this Controller controller) => controller.ViewError(new()
|
|
{
|
|
Title = "500",
|
|
Subtitle = "Der Zugangscode konnte nicht gesendet werden",
|
|
Body = "Bitte kontaktieren Sie das IT-Team."
|
|
});
|
|
|
|
public static ViewResult ViewInnerServiceError(this Controller controller) => controller.ViewError(new()
|
|
{
|
|
Title = "500",
|
|
Subtitle = "Ein unerwarteter Fehler ist aufgetreten",
|
|
Body = "Bitte kontaktieren Sie das IT-Team."
|
|
});
|
|
}
|
|
} |