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>
130 lines
4.3 KiB
C#
130 lines
4.3 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Helpers;
|
|
using Saxonite.Net.Core.Web.Online.App;
|
|
using Saxonite.Net.Core.Web.Online.Models;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Base.App;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Online Security Controller.
|
|
//=======================================================================
|
|
public partial class SecurityController : SaxController_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SecurityController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
|
base(localiser, logger)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
return RedirectToAction("Signin", "Security");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Signin()
|
|
{
|
|
// Redirect home if signed-in.
|
|
if (ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
Model_Security model = new Model_Security(Localiser);
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Security - Change password
|
|
/// <summary>
|
|
/// Security - Change Password action.
|
|
/// <para>- GET from request password email link.</para>
|
|
/// <para>- POST with user signed-in. Browser cache prohibited.</para>
|
|
/// </summary>
|
|
[HttpGet, HttpPost]
|
|
public IActionResult ChangePassword(Model_Security model)
|
|
{
|
|
String fn = GetType().Name + ".ChangePassword";
|
|
bool validSessionRequired = true;
|
|
|
|
if (Request.Method.EqualsCI(HttpMethods.Get))
|
|
{
|
|
// Check for encrypted parameters from 'Request Password' email link.
|
|
// NB Only allowed as a 'GET' request.
|
|
String encryptedParams = Request.Query[ParamName_RequestPasswordEncrypted];
|
|
RequestPasswordParams requestPasswordParams = ExtractRequestPasswordLinkParams(encryptedParams);
|
|
if (requestPasswordParams.IsValid())
|
|
{
|
|
String logSuffix = requestPasswordParams.GetValidParams().Concat("", " ", ".");
|
|
using (SaxUserAccount userAccount = AccountMgr.GetUserAccountById(requestPasswordParams.UserAccountId))
|
|
{
|
|
if (userAccount.IsStatusActive)
|
|
{
|
|
if (requestPasswordParams.IsValid(userAccount))
|
|
{
|
|
model.rpe = encryptedParams;
|
|
validSessionRequired = false;
|
|
}
|
|
else SaLogger.Warn(fn + " 'Request Password' parameters supplied but invalid. " + logSuffix);
|
|
}
|
|
else SaLogger.Warn(fn + " 'Request Password' parameters supplied but account is not active. " + logSuffix);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Must have a valid session to change password unless linked from Request Password above.
|
|
if (validSessionRequired && !ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
// Configure page.
|
|
model.PageCaption = Localiser["security.caption.change.password"];
|
|
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Security - Request Password
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Sign-in Request Password action.
|
|
/// <para>- User not signed-in.</para>
|
|
/// <para>- GET only with browser cache allowed.</para>
|
|
/// </summary>
|
|
[HttpGet]
|
|
public IActionResult RequestPassword()
|
|
{
|
|
Model_Security model = new Model_Security(Localiser);
|
|
|
|
// Configure page.
|
|
model.PageCaption = Localiser["security.caption.request.password"];
|
|
model.ProhibitCache = false;
|
|
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|