88 lines
3.0 KiB
C#
88 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Core.Web.Admin.Models;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
|
{
|
|
//=======================================================================
|
|
public class HomeController : SaxController_Admin
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public HomeController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
|
base(localiser, logger)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
String fn = GetType().Name + ".Index";
|
|
|
|
// Check for 'Keep Logged In' cookie.
|
|
// NB Only allowed if there isn't a current user session.
|
|
if (!ValidUserSession && SessionConfig.Security.SignIn.KeepLoggedIn.Allowed)
|
|
{
|
|
String encryptedParams = GetRequestCookie(CookieName_KeepLoggedIn);
|
|
KeepLoggedInParams keepLoggedInParams = ExtractKeepLoggedInParams(encryptedParams);
|
|
String logSuffix = keepLoggedInParams.GetValidParams().Concat("", " ", ".");
|
|
if (SysId.IsValid(keepLoggedInParams.UserAccountId))
|
|
{
|
|
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(keepLoggedInParams.UserAccountId);
|
|
if (userAccount != null)
|
|
{
|
|
if (userAccount.IsStatusActive)
|
|
{
|
|
String errorMessage = "";
|
|
if (SignUserIn(userAccount, AccountMgr.GetRolesForUser(userAccount.Id), true, ref errorMessage))
|
|
SaLogger.Info(fn + " Keep Logged In cookie found." + logSuffix);
|
|
else SaLogger.Warn(fn + " Keep Logged In cookie found but failed to sign user in: " + errorMessage + "." + logSuffix);
|
|
}
|
|
else SaLogger.Warn(fn + " Keep Logged In cookie found but UserAccount is not active." + logSuffix);
|
|
}
|
|
else SaLogger.Warn(fn + " Keep Logged In cookie found but UserAccount not found." + logSuffix);
|
|
}
|
|
}
|
|
|
|
// Redirect to sign-in if not signed-in.
|
|
if (!ValidUserSession)
|
|
{
|
|
ClearKeepLoggedInCookie();
|
|
return RedirectToAction("", "Security");
|
|
}
|
|
|
|
// Home page.
|
|
Model_Home model = new Model_Home(Localiser);
|
|
model.ProhibitCache = false;
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|