blob: 8ba9fec327d392c49522403251dd0b88503433f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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<SessionUser>(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);
}
}
}
|