Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes. - Relocate application and library projects while retaining Git rename history. - Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests. - Update Common integration, application version, and repository documentation. Application version: 1.3.0 Reviewed-on: #1 Co-authored-by: andy <andy@sarand.com>
104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Saxonite.Net.Core.Web.Online.Models;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
{
|
|
//=======================================================================
|
|
public class HomeController : SaxController_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public HomeController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
|
base(localiser, logger)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[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 && AppConfig.Security.SignIn.KeepLoggedIn.Allowed)
|
|
{
|
|
String encryptedParams = GetRequestCookie(KeepLoggedIn.CookieName);
|
|
KeepLoggedInParams keepLoggedInParams = ExtractKeepLoggedInParams(encryptedParams);
|
|
String logSuffix = keepLoggedInParams.GetValidParams().Concat("", " ", ".");
|
|
if (SysId.IsValid(keepLoggedInParams.UserAccountId))
|
|
{
|
|
// Record disposable items as they are created so all can be disposed when needed.
|
|
using (DisposableCollection<IDisposable> disposableItems = new DisposableCollection<IDisposable>())
|
|
{
|
|
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(keepLoggedInParams.UserAccountId);
|
|
if (userAccount != null)
|
|
{
|
|
disposableItems.Add(userAccount);
|
|
if (userAccount.IsStatusActive)
|
|
{
|
|
List<SaxUserRole> userRoles = AccountMgr.GetRolesForUser(userAccount.Id);
|
|
disposableItems.AddRange(userRoles);
|
|
List<SaxUserConfig> userConfigs = AccountMgr.GetConfigsForUser(userAccount.Id);
|
|
disposableItems.AddRange(userConfigs);
|
|
String errorMessage = "";
|
|
if (SignUserIn(userAccount, userRoles, userConfigs, 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);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
Model_Home model = new Model_Home(Localiser);
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel(Localiser) { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|