using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using System.Text.Json; using Tango.Portal.Chat.Web.Models; using Tango.Portal.Chat.Web.Utils; using Tango.Portal.Chat.Web.ViewModels; namespace Tango.Portal.Chat.Web.Controllers { public sealed class HomeController : Controller { public IActionResult Index(String session) { if (Debugger.IsAttached) { SessionUtils.SetSessionUser(HttpContext, new Models.SessionUser() { Name = "Debug User", Email = "roy@twine-s.com", FullName = "Debug User" }); HomeViewVM v = new HomeViewVM(); v.UserName = "Debug User"; return View(v); } String loginUrl = "https://twine-srv.com/login"; if (String.IsNullOrWhiteSpace(session)) return new RedirectResult(loginUrl); String json = String.Empty; try { json = SimpleCryptoHelper.Decrypt(session); } catch { return new RedirectResult(loginUrl); } var sessionUser = JsonSerializer.Deserialize(json); if (sessionUser == null || sessionUser.Expires < DateTime.UtcNow) { return new RedirectResult(loginUrl); } HomeViewVM vm = new HomeViewVM(); vm.UserName = sessionUser.Name; SessionUtils.SetSessionUser(HttpContext, sessionUser); return View(vm); } } }