From 729f91a18362cfb38b3ba8a5b2977ec59c3b7734 Mon Sep 17 00:00:00 2001 From: jojo aquino Date: Mon, 16 Dec 2024 17:31:00 +0000 Subject: [PATCH] redirect to Principal Dashboard --- .../Common/Services/CurrentUserService.cs | 2 ++ .../Common/Services/ICurrentUserService.cs | 7 ++++-- .../EnotaryoPH.Web/EnotaryoPH.Web.csproj | 2 +- .../EnotaryoPH.Web/Pages/Index.cshtml.cs | 24 ++++++++++++------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/EnotaryoPH/EnotaryoPH.Web/Common/Services/CurrentUserService.cs b/EnotaryoPH/EnotaryoPH.Web/Common/Services/CurrentUserService.cs index 29931a4..7ab8327 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Common/Services/CurrentUserService.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Common/Services/CurrentUserService.cs @@ -11,6 +11,8 @@ namespace EnotaryoPH.Web.Common.Services public string? GetEmail() => _user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value; + public string? GetRole() => _user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value; + public Guid GetUser_UID() { if (_user == null) diff --git a/EnotaryoPH/EnotaryoPH.Web/Common/Services/ICurrentUserService.cs b/EnotaryoPH/EnotaryoPH.Web/Common/Services/ICurrentUserService.cs index dd4cf13..88ecec8 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Common/Services/ICurrentUserService.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Common/Services/ICurrentUserService.cs @@ -1,10 +1,13 @@ - -namespace EnotaryoPH.Web.Common.Services +namespace EnotaryoPH.Web.Common.Services { public interface ICurrentUserService { string? GetEmail(); + + string? GetRole(); + Guid GetUser_UID(); + bool IsAuthenticated(); } } \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/EnotaryoPH.Web.csproj b/EnotaryoPH/EnotaryoPH.Web/EnotaryoPH.Web.csproj index 7586d47..4b4417b 100644 --- a/EnotaryoPH/EnotaryoPH.Web/EnotaryoPH.Web.csproj +++ b/EnotaryoPH/EnotaryoPH.Web/EnotaryoPH.Web.csproj @@ -1,4 +1,4 @@ - + net9.0 diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Index.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Index.cshtml.cs index 15a19ae..cc106ec 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Index.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Index.cshtml.cs @@ -1,21 +1,27 @@ -using EnotaryoPH.Data; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace EnotaryoPH.Web.Pages { public class IndexModel : PageModel { - private readonly ILogger _logger; - private readonly NotaryoDBContext _notaryoDBContext; + private readonly ICurrentUserService _currentUserService; - public IndexModel(ILogger logger, NotaryoDBContext notaryoDBContext) - { - _logger = logger; - _notaryoDBContext = notaryoDBContext; - } + public IndexModel(ICurrentUserService currentUserService) => _currentUserService = currentUserService; - public void OnGet() + public IActionResult OnGet() { + if (_currentUserService.IsAuthenticated() == false) + { + return Page(); + } + + if (_currentUserService.GetRole() == "Principal") + { + return RedirectToPage("/Principal/Dashboard/Dashboard"); + } + + return Page(); } } } \ No newline at end of file