aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/HomeController.cs
blob: f83749f468ecf72fced491fc9eec52b570f7c4eb (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
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
using Tango.Portal.Chat.Web.ViewModels;

namespace Tango.Portal.Chat.Web.Controllers
{
    public sealed class HomeController : Controller
    {
        public IActionResult Index(String session)
        {
            String loginUrl = "https://twine-srv.com/login";

            if (String.IsNullOrWhiteSpace(session)) return new RedirectResult(loginUrl);

            String decryptedSession = String.Empty;

            try
            {
                decryptedSession = SimpleCryptoHelper.Decrypt(session);
            }
            catch
            {
                return new RedirectResult(loginUrl);
            }

            var template = new { UserName = "", Expires = DateTime.MinValue };

            var sessionUser = JsonSerializer.Deserialize(decryptedSession, template.GetType());
            if (sessionUser == null || (DateTime)(sessionUser as dynamic).Expires < DateTime.UtcNow)
            {
                return new RedirectResult(loginUrl);
            }

            HomeViewVM vm = new HomeViewVM();
            vm.UserName = (sessionUser as dynamic).UserName;
            return View(vm);
        }
    }
}