Fixed user being able to go to login screen despite being logged in

This commit is contained in:
Luke Else 2022-02-28 22:00:35 +00:00
parent 72124e7f15
commit 27bf158a7a
2 changed files with 11 additions and 4 deletions

View File

@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using EFB.Sessions;
namespace EFB.Controllers namespace EFB.Controllers
{ {
@ -16,6 +18,10 @@ namespace EFB.Controllers
public IActionResult Index() public IActionResult Index()
{ {
//Ensure that the user is not already logged in
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user != null) return RedirectToAction("Index", "App");
return View(); return View();
} }

View File

@ -26,9 +26,11 @@ namespace EFB.Controllers
return View(); return View();
} }
public async Task<IActionResult> Login(string email, string password) public async Task<IActionResult> Login(string email, string password)
{ {
//Ensure that the user is not already logged in
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user != null) return RedirectToAction("Index", "App");
if (!Form.FormAuthenticator.ValidateEMail(email)) if (!Form.FormAuthenticator.ValidateEMail(email))
{ {
@ -70,7 +72,7 @@ namespace EFB.Controllers
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }
UserModel user = new UserModel user = new UserModel
{ {
EMail = email, EMail = email,
UserToken = new TokenModel UserToken = new TokenModel
@ -83,7 +85,6 @@ namespace EFB.Controllers
//Using Session Extensions (Store the user session) //Using Session Extensions (Store the user session)
HttpContext.Session.SetObject("User", user); HttpContext.Session.SetObject("User", user);
return RedirectToAction("Index", "App"); return RedirectToAction("Index", "App");
} }
public IActionResult Logout() public IActionResult Logout()