89 lines
2.6 KiB
C#
89 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using IdentityServer4.Services;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using nuget_host.Entities;
|
|
using nuget_host.Models;
|
|
|
|
namespace nuget_host.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IIdentityServerInteractionService _interaction;
|
|
private readonly ILogger _logger;
|
|
readonly IHostingEnvironment _environment;
|
|
public IDataProtector DataProtector { get; }
|
|
public SmtpSettings Options { get; } //set only via Secret Manager
|
|
|
|
public HomeController(
|
|
IOptions<SmtpSettings> smtpSettings,
|
|
IDataProtectionProvider provider,
|
|
IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger<HomeController> logger)
|
|
{
|
|
_interaction = interaction;
|
|
_environment = environment;
|
|
_logger = logger;
|
|
Options = smtpSettings.Value;
|
|
DataProtector = provider.CreateProtector(Options.ProtectionTitle);
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult About()
|
|
{
|
|
ViewData["Message"] = "Your application description page.";
|
|
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Contact()
|
|
{
|
|
ViewData["Message"] = "Your contact page.";
|
|
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Privacy()
|
|
{
|
|
ViewData["Message"] = "Your Privacy page.";
|
|
|
|
return Ok(ViewData);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Shows the error page
|
|
/// </summary>
|
|
public async Task<IActionResult> Error(string errorId)
|
|
{
|
|
var vm = new ErrorViewModel();
|
|
|
|
// retrieve error details from identityserver
|
|
var message = await _interaction.GetErrorContextAsync(errorId);
|
|
if (message != null)
|
|
{
|
|
vm.Error = message;
|
|
|
|
if (!_environment.IsDevelopment())
|
|
{
|
|
// only show in development
|
|
message.ErrorDescription = null;
|
|
}
|
|
}
|
|
|
|
return View("Error", vm);
|
|
}
|
|
|
|
}
|
|
}
|