Add project files.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Security;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
public class HomeController : Controller_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public HomeController (OpnLocaliser localiser) : base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Home - Index.
|
||||
public IActionResult Index (Models.Model_Home_Index model)
|
||||
{
|
||||
Logger.Debug(GetType().Name + ".Index");
|
||||
if (HttpContext.Session != null)
|
||||
{
|
||||
foreach (var sessionKey in HttpContext.Session.Keys)
|
||||
{
|
||||
Logger.Debug(GetType().Name + ".Index Session key: " + sessionKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Actions.
|
||||
if (model.FormAction.EqualsCI(Localiser.GetText("form.action.login")))
|
||||
{
|
||||
// Validate login properties.
|
||||
if (StringUtil.IsEmpty(model.UserCode))
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.login.userCode.missing"));
|
||||
|
||||
// Retrieve session context.
|
||||
OpnSessionContext sessionContext = null;
|
||||
if (model.OK)
|
||||
{
|
||||
sessionContext = GetSessionContext(model.InstanceIdx);
|
||||
if (sessionContext == null)
|
||||
{
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.sessionContext.unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve security console.
|
||||
SaSecurityConsole securityConsole = null;
|
||||
if (model.OK)
|
||||
{
|
||||
securityConsole = OpnGlobals.ConsoleHelper.GetSecurityConsole(sessionContext);
|
||||
if (securityConsole == null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.securityConsole.unavailable"));
|
||||
}
|
||||
|
||||
// Retrieve and validate user.
|
||||
SaSecurityItem secItemUser = null;
|
||||
if (model.OK)
|
||||
{
|
||||
secItemUser = securityConsole.GetUserByCode(model.UserCode);
|
||||
if (secItemUser == null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.login.credentials.invalid"));
|
||||
}
|
||||
// Start user session.
|
||||
if (model.OK)
|
||||
{
|
||||
if (OpenUserSession(sessionContext, secItemUser.Id, secItemUser.Code, secItemUser.Description))
|
||||
Logger.Info("User logged in: " + secItemUser.Description + ". Instance: " + sessionContext.InstanceCode);
|
||||
}
|
||||
}
|
||||
else if (model.FormAction.EqualsCI(Localiser.GetText("form.action.logout")))
|
||||
{
|
||||
// Make a note of the session index for the login form.
|
||||
model.InstanceIdx = model.SessionIdx;
|
||||
|
||||
// Clear user session.
|
||||
// NB Session Data may not be available, eg. if session has timed out.
|
||||
if (SessionData != null)
|
||||
{
|
||||
String userName = SessionData.User.Name;
|
||||
String instanceCode = OpnSystem.GetInstanceCode(SessionData.Instance);
|
||||
Logger.Info("User logging out: " + userName + ". Instance: " + instanceCode);
|
||||
}
|
||||
else Logger.Warn("User logging out - session has expired.");
|
||||
CloseUserSession();
|
||||
}
|
||||
else if (model.SessionExpired != null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.session.expired"));
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public IActionResult Error ()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user