v1.2.11.2

This commit is contained in:
2024-02-27 15:45:47 +00:00
parent 52232331f8
commit 9643447b85
90 changed files with 2010 additions and 688 deletions
@@ -26,6 +26,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
{
public String Caption { get; set; }
public AjaxResponse_Data.ItemLabelValue Awaiting { get; set; }
public String UsersLink { get; set; }
public String AwaitingLink { get; set; }
public List<AjaxResponse_Data.ItemLabelValue> OnlineStats { get; set; }
public String OnlineLink { get; set; }
@@ -35,6 +36,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
{
public String Caption { get; set; }
public AjaxResponse_Data.ItemLabelValue Awaiting { get; set; }
public String OrganisationsLink { get; set; }
public String AwaitingLink { get; set; }
}
public OrganisationStatsData Organisation { get; } = new OrganisationStatsData();
@@ -98,10 +100,12 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
{
case Sax.DataItemType.UserAccount:
responseData.Stats.User.Awaiting = new AjaxResponse_Data.ItemLabelValue() { Label = Localiser["label.awaiting.activation"], Value = itemCount.ToString() };
responseData.Stats.User.UsersLink = Url.Action("", "User").TrimStart('/');
responseData.Stats.User.AwaitingLink = Url.Action("", "User", new RouteValueDictionary() { { "sta", "Await" } }).TrimStart('/');
break;
case Sax.DataItemType.Organisation:
responseData.Stats.Organisation.Awaiting = new AjaxResponse_Data.ItemLabelValue() { Label = Localiser["label.awaiting.activation"], Value = itemCount.ToString() };
responseData.Stats.Organisation.OrganisationsLink = Url.Action("", "Organisation").TrimStart('/');
responseData.Stats.Organisation.AwaitingLink = Url.Action("", "Organisation", new RouteValueDictionary() { { "sta", "Await" } }).TrimStart('/');
break;
}
@@ -36,30 +36,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
{
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))
{
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);
}
}
if (!ValidUserSession)
AutoLoginUser();
// Redirect to sign-in if not signed-in.
if (!ValidUserSession)
@@ -0,0 +1,145 @@
using Microsoft.AspNetCore.Mvc;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Email;
using Sarand.Net.Standard.Base.Utils;
using Saxonite.Net.Core.Web.Admin.Consoles;
using Saxonite.Net.Core.Web.Admin.Models;
using Saxonite.Net.Core.Web.Admin.Procs;
using Saxonite.Net.Standard.Base.App;
using Saxonite.Net.Standard.Base.Bus;
using Saxonite.Net.Standard.Base.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Saxonite.Net.Core.Web.Admin.Controllers
{
//=======================================================================
// Controller: Organisation - Ajax - Upload
//=======================================================================
partial class OrganisationController
{
//-------------------------------------------------------------------
// Definitions.
//-------------------------------------------------------------------
// Organisation Uploader process info.
//-------------------------------------------------------------------
private class AjaxResponse_OrganisationUploadInfo : AjaxResponse_Data
{
// Construction.
public AjaxResponse_OrganisationUploadInfo(SaxModel_Admin model) : base(model) { }
}
//-------------------------------------------------------------------
[HttpPost]
[Route("Organisation/Ajax/UploadInfo")]
public IActionResult Ajax_OrganisationUploadInfo(SaxModel_Admin model)
{
String fn = GetType().Name + ".Ajax_OrganisationUploadInfo";
String messageTitle = Localiser["caption.upload.organisations"];
AjaxResponse_OrganisationUploadInfo responseData = new AjaxResponse_OrganisationUploadInfo(model);
// Validate session.
if (!ValidUserSession)
return GetAjaxResult_InvalidSession(responseData);
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
{
// Process console.
SaxProcessConsole_Admin processConsole = GetProcessConsole_Admin(SessionContext);
if (processConsole == null)
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
try
{
// Check whether upload is in progress.
if (processConsole.IsProcessing(SaxProcessConsole_Admin.ProcessType.OrganisationUpload))
return Json(responseData.SetMessage(messageTitle, Localiser["msg.process.in.progress"]));
}
catch (Exception exc)
{
SaLogger.Warn(fn + " " + exc.GetType().Name + " initialising organisation uploader.");
return Json(responseData.SetMessage(messageTitle, exc.GetType().Name + " initialising organisation uploader."));
}
}
// Complete response.
responseData.Success = true;
return Json(responseData);
}
//-------------------------------------------------------------------
// Upload Organisations.
//-------------------------------------------------------------------
private class AjaxResponse_OrganisationUpload : AjaxResponse_Data
{
// Construction.
public AjaxResponse_OrganisationUpload(SaxModel_Admin model) : base(model) { }
}
//-------------------------------------------------------------------
[HttpPost]
[Route("Organisation/Ajax/Upload")]
public IActionResult Ajax_UploadOrganisations(Model_OrganisationUpload model)
{
String fn = GetType().Name + ".Ajax_UploadOrganisations";
String messageTitle = Localiser["caption.upload.organisations"];
AjaxResponse_OrganisationUpload responseData = new AjaxResponse_OrganisationUpload(model);
// Validate session.
if (!ValidUserSession)
return GetAjaxResult_InvalidSession(responseData);
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
{
// Validate supplied data properties.
if (!model.ValidateProperties(responseData))
return Json(responseData);
// Process console.
SaxProcessConsole_Admin processConsole = GetProcessConsole_Admin(SessionContext);
if (processConsole == null)
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
try
{
// Check whether upload is in progress.
if (processConsole.IsProcessing(SaxProcessConsole_Admin.ProcessType.OrganisationUpload))
return Json(responseData.SetMessage(messageTitle, Localiser["msg.process.in.progress"]));
// Create the upload process.
SaxOrganisationUploader.Config processConfig = new SaxOrganisationUploader.Config(SessionContext, model.OrganisationDataFile[0]);
processConfig.SheetNameOrNumber = model.SheetNameOrNumber;
SaxOrganisationUploader process = new SaxOrganisationUploader(processConfig);
// Store the process and run.
processConsole.SetProcess(process);
process.RunAsync();
}
catch (Exception exc)
{
SaLogger.Warn(fn + " " + exc.GetType().Name + " initialising organisation uploader.");
return Json(responseData.SetMessage(messageTitle, exc.GetType().Name + " initialising organisation uploader."));
}
}
// Complete response.
responseData.Success = true;
return Json(responseData);
}
//-------------------------------------------------------------------
}
}
@@ -5,8 +5,10 @@ using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.Utils;
using Saxonite.Net.Core.Web.Admin.Models;
using Saxonite.Net.Core.Web.Admin.Procs;
using Saxonite.Net.Standard.Base.App;
using Saxonite.Net.Standard.Base.Bus;
using Saxonite.Net.Standard.Base.Mgr;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -126,6 +128,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public List<AjaxResponse_Data.ItemCodeDesc> ContactMethods { get; } = new List<ItemCodeDesc>();
public List<CodeDesc> Statuses { get; } = new List<CodeDesc>();
public String DefaultStatusCode { get; set; }
public List<String> UploadContentTypes { get; set; }
}
//-------------------------------------------------------------------
[HttpPost]
@@ -154,6 +157,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
responseData.Statuses.Add(SacsSystem.GetStatusCode(status), Localiser.GetStatusCaption(status));
responseData.DefaultStatusCode = SacsSystem.GetStatusCode(SaxOrganisation.DefaultStatus);
// Reference data - Image content types.
responseData.UploadContentTypes = SaxOrganisationUploader.ValidContentTypes;
// Store filter values.
SysId filterSportId = model.Filter.OrganisationSportId.ToSysId();
SessionData_Admin.Filter.SportId = SysId.IsValid(filterSportId) ? filterSportId : null;
@@ -161,14 +167,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
SessionData_Admin.Filter.RegionId = SysId.IsValid(filterRegionId) ? filterRegionId : null;
// Item filter.
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
prmOrganisation.OrganisationType = model.FilterOrganisationType;
prmOrganisation.OrganisationCategory = model.FilterOrganisationCategory;
prmOrganisation.SportIdsIncluded.AddId(filterSportId);
prmOrganisation.RegionIdsIncluded.AddId(filterRegionId);
prmOrganisation.StatusCat = model.Filter.OrganisationStatusCategoryCode != null ? model.FilterOrganisationStatusCategory : SaxOrganisation.StatusCat.NotDeleted;
prmOrganisation.SortColumns.Add(AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name));
SaxOrganisation.Params prmOrganisation = GetOrganisationListFilter(model, AccountMgr);
model.Paging.ItemTotal = (ulong)AccountMgr.GetOrganisationCount(prmOrganisation);
model.PopulatePagingTo(prmOrganisation.ResultsPaging);
@@ -237,6 +236,27 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
return Json(responseData);
}
//-------------------------------------------------------------------
/// <summary>
/// Construct Organisation filter params.
/// <para>- Shared with Organisation Exporter process.</para>
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static SaxOrganisation.Params GetOrganisationListFilter(Model_Organisation model, SaxAccountMgr accountMgr)
{
// Item filter.
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
prmOrganisation.OrganisationType = model.FilterOrganisationType;
prmOrganisation.OrganisationCategory = model.FilterOrganisationCategory;
prmOrganisation.SportIdsIncluded.AddId(model.Filter.OrganisationSportId.ToSysId());
prmOrganisation.RegionIdsIncluded.AddId(model.Filter.OrganisationRegionId.ToSysId());
prmOrganisation.StatusCat = model.Filter.OrganisationStatusCategoryCode != null ? model.FilterOrganisationStatusCategory : SaxOrganisation.StatusCat.NotDeleted;
prmOrganisation.SortColumns.Add(accountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name));
return prmOrganisation;
}
//-------------------------------------------------------------------
// Get Organisation ajax request.
//-------------------------------------------------------------------
@@ -0,0 +1,79 @@
using Microsoft.AspNetCore.Mvc;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Email;
using Sarand.Net.Standard.Base.Helpers;
using Sarand.Net.Standard.Base.Utils;
using Sarand.Net.Standard.Proc.Excel;
using Saxonite.Net.Core.Web.Admin.Consoles;
using Saxonite.Net.Core.Web.Admin.Models;
using Saxonite.Net.Core.Web.Admin.Procs;
using Saxonite.Net.Core.Web.Base.Controllers;
using Saxonite.Net.Standard.Base.App;
using Saxonite.Net.Standard.Base.Bus;
using Saxonite.Net.Standard.Base.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Saxonite.Net.Core.Web.Admin.Controllers
{
//=======================================================================
// Controller: Organisation - Download
//=======================================================================
partial class OrganisationController
{
//-------------------------------------------------------------------
// Definitions.
//-------------------------------------------------------------------
// Download Organisations.
//-------------------------------------------------------------------
[HttpPost]
[Route("Organisation/Download")]
public IActionResult Ajax_DownloadOrganisations(Model_OrganisationDownload model)
{
String fn = GetType().Name + ".Ajax_DownloadOrganisations";
// Validate session.
if (!ValidUserSession)
return Unauthorized();
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
{
// Validate supplied data properties.
if (!model.ValidateProperties())
return BadRequest();
// Export data.
SaxOrganisationExporter.Config exporterConfig = new SaxOrganisationExporter.Config(SessionContext, GetOrganisationListFilter(model, AccountMgr));
exporterConfig.Format = SaxOrganisationExporter.ExportFormat.Excel_Open;
exporterConfig.IncludeId = StringUtil.ToBool(model.IncludeId);
SaxOrganisationExporter exporter = new SaxOrganisationExporter(exporterConfig);
if (exporter.RunProcess())
{
// Organisations exported successfully.
byte[] data = exporter.GetDocumentData();
using (MemoryStream content = new MemoryStream(data))
{
String contentType = exporter.GetContentType();
var fileName = "Sportierre-Organisations-" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";
return File(content.ToArray(), contentType, fileName);
}
}
else
{
// Problems occurred.
}
}
return NoContent();
}
//-------------------------------------------------------------------
}
}
@@ -29,6 +29,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Index(String sta)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -64,6 +66,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Members(Model_OrganisationMembers model)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -90,6 +94,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Associations(Model_OrganisationAssociations model)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -26,6 +26,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Index()
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -6,6 +6,7 @@ using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Helpers;
using Sarand.Net.Standard.Base.Utils;
using Saxonite.Net.Core.Web.Admin.App;
using Saxonite.Net.Core.Web.Admin.Consoles;
using Saxonite.Net.Core.Web.Base.App;
using Saxonite.Net.Core.Web.Base.Controllers;
using Saxonite.Net.Standard.Base.App;
@@ -41,6 +42,15 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
return JsonConvert.DeserializeObject<SaxSessionData_Admin>(sessionDataJson, SaxSessionDataJsonSerializerSettings);
}
//-------------------------------------------------------------------
// Globals.
//-------------------------------------------------------------------
protected SaxConsoleHelper_Admin ConsoleHelper_Admin { get { return ConsoleHelper as SaxConsoleHelper_Admin; } }
protected SaxProcessConsole_Admin GetProcessConsole_Admin(SaxSessionContext sessionContext)
{
return ConsoleHelper_Admin?.GetProcessConsole(sessionContext) as SaxProcessConsole_Admin;
}
//-------------------------------------------------------------------
// User Session.
//-------------------------------------------------------------------
@@ -50,54 +60,60 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
/// <para>- Open user session - store details against Sesion Data.</para>
/// <para>- Set 'Keep logged in' cookie if required.</para>
/// </summary>
protected bool SignUserIn(SaxUserAccount userAccount, List<SaxUserRole> userRoles, bool keepLoggedIn, ref String errorMessage)
protected bool SignUserIn(SaxUserAccount userAccount, bool keepLoggedIn, ref String errorMessage)
{
String fn = GetType().Name + ".SignUserIn";
// Validate User Account, just in case - should have been done before arriving here!
if (userAccount == null)
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
{
SaLogger.Error(fn + " Unable to sign account in - null user account.");
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
List<SaxUserRole> userRoles = AccountMgr.GetRolesForUser(userAccount.Id);
disposableItems.AddRange(userRoles);
// Validate User Account, just in case - should have been done before arriving here!
if (userAccount == null)
{
SaLogger.Error(fn + " Unable to sign account in - null user account.");
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
if (!userAccount.IsStatusActive)
{
SaLogger.Error(fn + " Unable to sign account in - user account is not active. Email: " + userAccount.EmailAddress);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
// 'Keep logged in' can be switched off by the application configuration.
keepLoggedIn = App.AppConfig.Security.SignIn.KeepLoggedIn.Allowed && keepLoggedIn;
// Log user in - Admin details stored against System Admin role.
SaxUserRole userRole = userRoles.Find(item => item.UserRole == Sax.UserRole.SystemAdmin);
if (userRole == null)
{
SaLogger.Warn(fn + " System Admin role not found for " + userAccount.EmailAddress);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
userRole.KeepLoggedIn = keepLoggedIn;
userRole.LastLoginAt = DateTime.Now;
userRole.InvalidLoginCount = 0;
userRole.LastInvalidLoginAt = DateTime.MinValue;
if (!AccountMgr.UpdateUserRole(userRole, DbUpdateInfo))
{
SaLogger.Warn(fn + " Failed to update Admin user role for " + userAccount.EmailAddress + ": " + AccountMgr.ErrorStateMessage);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
SaLogger.Info(fn + " User session opened for " + userAccount.EmailAddress, true);
// Create session.
OpenUserSession(SessionContext, userAccount, userRoles);
// Send the 'Keep Logged In' cookie if requested.
if (userRole.KeepLoggedIn)
SetKeepLoggedInCookie();
}
if (!userAccount.IsStatusActive)
{
SaLogger.Error(fn + " Unable to sign account in - user account is not active. Email: " + userAccount.EmailAddress);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
// 'Keep logged in' can be switched off by the application configuration.
keepLoggedIn = App.AppConfig.Security.SignIn.KeepLoggedIn.Allowed && keepLoggedIn;
// Log user in - Admin details stored against System Admin role.
SaxUserRole userRole = userRoles.Find(item => item.UserRole == Sax.UserRole.SystemAdmin);
if (userRole == null)
{
SaLogger.Warn(fn + " System Admin role not found for " + userAccount.EmailAddress);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
userRole.KeepLoggedIn = keepLoggedIn;
userRole.LastLoginAt = DateTime.Now;
userRole.InvalidLoginCount = 0;
userRole.LastInvalidLoginAt = DateTime.MinValue;
if (!AccountMgr.UpdateUserRole(userRole, DbUpdateInfo))
{
SaLogger.Warn(fn + " Failed to update Admin user role for " + userAccount.EmailAddress + ": " + AccountMgr.ErrorStateMessage);
errorMessage = Localiser["security.msg.signin.invalid"];
return false;
}
SaLogger.Info(fn + " User session opened for " + userAccount.EmailAddress, true);
// Create session.
OpenUserSession(SessionContext, userAccount, userRoles);
// Send the 'Keep Logged In' cookie if requested.
if (userRole.KeepLoggedIn)
SetKeepLoggedInCookie();
return true;
}
@@ -121,22 +137,50 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
}
//-------------------------------------------------------------------
// IMage utilities.
// Keep Logged In.
//-------------------------------------------------------------------
/// <summary>
/// Construct URL to display Organisation logo.
/// <para>- Option to allow for 'Upload' image if active.</para>
/// Check for 'Keep Logged In' cookie and auto-login user if details are valid.
/// </summary>
protected String GetOrganisationLogoLink(SysId organisationId, bool uploadImage)
/// <returns></returns>
protected bool AutoLoginUser()
{
String imageLink = "Image/Organisation/Logo" + (uploadImage ? "/Upload" : "") + "?";
NameValueCollection parameters = new NameValueCollection();
parameters.Add(ImageController.ParamName_OrganisationId, SysId.ToString(organisationId));
return imageLink + ImageController.ParamName_OrganisationLogoEncrypted + "=" + EncryptSessionParams(parameters);
String fn = "AutoLoginUser";
// NB Only allowed if there isn't a current user session.
if (ValidUserSession) return true;
if (!AppConfig.Security.SignIn.KeepLoggedIn.Allowed) return false;
// Extract cookie details.
String encryptedParams = GetRequestCookie(KeepLoggedIn.CookieName);
KeepLoggedInParams keepLoggedInParams = ExtractKeepLoggedInParams(encryptedParams);
String logSuffix = keepLoggedInParams.GetValidParams().Concat("", " ", ".");
if (SysId.IsValid(keepLoggedInParams.UserAccountId))
{
using (SaxUserAccount userAccount = AccountMgr.GetUserAccountById(keepLoggedInParams.UserAccountId))
{
if (userAccount != null)
{
if (userAccount.IsStatusActive)
{
String errorMessage = "";
if (SignUserIn(userAccount, true, ref errorMessage))
{
// Successful login.
SaLogger.Info(fn + " Keep Logged In cookie found." + logSuffix);
return true;
}
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);
}
}
ClearKeepLoggedInCookie();
return false;
}
//-------------------------------------------------------------------
// Keep Logged In.
//-------------------------------------------------------------------
/// <summary>Keep-Logged-In cookie.</summary>
protected void SetKeepLoggedInCookie()
@@ -164,8 +208,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
// - IV Must be regenerated if key is changed: uncomment 'Generated' variable and copy resulting value to IV variable.
public static class KeepLoggedIn
{
public static String CookieName = "SXKLI";
public static String Base64Key = SacsEncryptionHelper.EncodePlainKey("<=Saxonite^{kEEp+1Ogg3d-IN}~32*>", SacsEncryptionHelper.KeyLength);
public static String CookieName = "SXKLI";
public static String Base64Key = SacsEncryptionHelper.EncodePlainKey("<=Saxonite^{kEEp+1Ogg3d-IN}~32*>", SacsEncryptionHelper.KeyLength);
public static String Base64IV = "YOX10FIPp1zM1pg5U6fW7A==";
private static String Base64IV_Generated = SacsEncryptionHelper.InitSymmetricEncryptionIV(KeepLoggedIn.Base64Key);
}
@@ -205,12 +249,27 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
return keepLoggedInParams;
}
//-------------------------------------------------------------------
// Image utilities.
//-------------------------------------------------------------------
/// <summary>
/// Construct URL to display Organisation logo.
/// <para>- Option to allow for 'Upload' image if active.</para>
/// </summary>
protected String GetOrganisationLogoLink(SysId organisationId, bool uploadImage)
{
String imageLink = "Image/Organisation/Logo" + (uploadImage ? "/Upload" : "") + "?";
NameValueCollection parameters = new NameValueCollection();
parameters.Add(ImageController.ParamName_OrganisationId, SysId.ToString(organisationId));
return imageLink + ImageController.ParamName_OrganisationLogoEncrypted + "=" + EncryptSessionParams(parameters);
}
//-------------------------------------------------------------------
// Parameter encryption, eg. for images.
//-------------------------------------------------------------------
// Encryption key is the same for all users each time the application is started,
// but a different IV value is generated for each session so that the links/parameters cannot be shared.
public static String Base64Key_AdminApp { get; } = SacsEncryptionHelper.EncodePlainKey("Saxonite&Admin#Encryption-"+DateTime.Today.Format("ddMMyy"), SacsEncryptionHelper.KeyLength);
public static String Base64Key_AdminApp { get; } = SacsEncryptionHelper.EncodePlainKey("Saxonite&Admin#Encryption-" + DateTime.Today.Format("ddMMyy"), SacsEncryptionHelper.KeyLength);
protected String EncryptSessionParams(NameValueCollection parameters)
{
return HttpUtility.UrlEncode(EncryptParameters(parameters, SessionData_Admin.Base64IV_AdminApp, Base64Key_AdminApp));
@@ -56,7 +56,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
return Json(responseData);
String errorMessage = "";
if (!SignUserIn(userAccount, AccountMgr.GetRolesForUser(userAccount.Id), model.KeepMeSignedIn, ref errorMessage))
if (!SignUserIn(userAccount, model.KeepMeSignedIn, ref errorMessage))
{
return Json(responseData.SetControlError(nameof(model.EmailAddress), errorMessage));
}
@@ -26,6 +26,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Index()
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -23,7 +23,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
//=======================================================================
// System - Ajax - Database controller
//=======================================================================
partial class SystemController : SaDbProcess_CompareDatabaseSchemas.IProcessNotifier
partial class SystemController
{
//-------------------------------------------------------------------
// Database data.
@@ -169,14 +169,14 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
SaDbProcess_ConvertDbSchema.Config cfgSchemaConvert = new SaDbProcess_ConvertDbSchema.Config();
SaDbProcess_ConvertDbSchema procSchemaConvert = new SaDbProcess_ConvertDbSchema(cfgSchemaConvert);
List<DbDfnTable> tables = procSchemaConvert.ConvertXmlToTables(xmlSchema);
if (procSchemaConvert.HasProcessError())
return Json(responseData.SetMessage(messageTitle, "Failed to convert XML schema: " + procSchemaConvert.GetProcessError()));
if (procSchemaConvert.HasErrorMessage())
return Json(responseData.SetMessage(messageTitle, "Failed to convert XML schema: " + procSchemaConvert.GetErrorMessage()));
SaDbProcess_CompareDatabaseSchemas.Config cfgSchemaCompare = new SaDbProcess_CompareDatabaseSchemas.Config(tables, db);
cfgSchemaCompare.HideIdenticalObjects = true;
cfgSchemaCompare.IgnorePosition = true;
SaDbProcess_CompareDatabaseSchemas procSchemaCompare = new SaDbProcess_CompareDatabaseSchemas(cfgSchemaCompare);
procSchemaCompare.ProcessNotifier = this;
procSchemaCompare.OnSchemaComparisonItemAdded += OnSchemaComparisonItemAdded;
procSchemaCompare.RunProcess();
List<SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItem> schemaComparisonItems = procSchemaCompare.GetSchemaComparisonItems();
@@ -200,17 +200,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
return Json(responseData);
}
public void OnStartProcess()
{
}
public void SetProgressInfo(List<string> progressInfo)
{
}
public void OnEndProcess()
{
}
public void OnSchemaComparisonItemAdded(SaDbProcess_CompareDatabaseSchemas proc)
// Processing events.
public void OnSchemaComparisonItemAdded(object sender, SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItemAddedEventArgs e)
{
SaDbProcess_CompareDatabaseSchemas proc = sender as SaDbProcess_CompareDatabaseSchemas;
}
//-------------------------------------------------------------------
@@ -45,6 +45,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Database(Model_System model)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -60,6 +62,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Logs(Model_System model)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -28,6 +28,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Index(String sta)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");
@@ -28,6 +28,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
public IActionResult Index(String sta)
{
// Validate session.
if (!ValidUserSession)
AutoLoginUser();
if (!ValidUserSession)
return RedirectToAction("", "");