isn/Controllers/HomeController.cs

88 lines
2.6 KiB
C#
Raw Normal View History

2021-04-08 02:03:17 +01:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
2021-04-11 22:39:26 +01:00
using IdentityServer4.Services;
2021-04-25 12:12:50 +01:00
using Microsoft.AspNetCore.DataProtection;
2021-04-11 22:39:26 +01:00
using Microsoft.AspNetCore.Hosting;
2021-04-08 02:03:17 +01:00
using Microsoft.AspNetCore.Mvc;
2021-04-11 22:39:26 +01:00
using Microsoft.Extensions.Logging;
2021-04-25 12:12:50 +01:00
using Microsoft.Extensions.Options;
using nuget_host.Entities;
2021-04-08 02:03:17 +01:00
using nuget_host.Models;
namespace nuget_host.Controllers
{
public class HomeController : Controller
{
2021-04-11 22:39:26 +01:00
private readonly IIdentityServerInteractionService _interaction;
private readonly ILogger _logger;
2021-04-25 12:12:50 +01:00
readonly IHostingEnvironment _environment;
public IDataProtector DataProtector { get; }
public SmtpSettings Options { get; } //set only via Secret Manager
2021-04-11 22:39:26 +01:00
2021-04-25 12:12:50 +01:00
public HomeController(
IOptions<SmtpSettings> smtpSettings,
IDataProtectionProvider provider,
IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger<HomeController> logger)
2021-04-11 22:39:26 +01:00
{
_interaction = interaction;
_environment = environment;
_logger = logger;
2021-04-25 12:12:50 +01:00
Options = smtpSettings.Value;
DataProtector = provider.CreateProtector(Options.ProtectionTitle);
2021-04-11 22:39:26 +01:00
}
2021-04-08 02:03:17 +01:00
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();
}
2021-04-25 12:12:50 +01:00
public IActionResult Privacy()
2021-04-08 02:03:17 +01:00
{
2021-04-25 12:12:50 +01:00
ViewData["Message"] = "Your Privacy page.";
2021-04-08 02:03:17 +01:00
return Ok(ViewData);
}
2021-04-11 22:39:26 +01:00
/// <summary>
/// Shows the error page
/// </summary>
public async Task<IActionResult> Error(string errorId)
2021-04-08 02:03:17 +01:00
{
2021-04-11 22:39:26 +01:00
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);
2021-04-08 02:03:17 +01:00
}
2021-04-11 22:39:26 +01:00
2021-04-08 02:03:17 +01:00
}
}