redirect to Principal Dashboard

This commit is contained in:
jojo aquino 2024-12-16 17:31:00 +00:00
parent 1b17da99b0
commit 729f91a183
4 changed files with 23 additions and 12 deletions

View File

@ -11,6 +11,8 @@ namespace EnotaryoPH.Web.Common.Services
public string? GetEmail() => _user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value; 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() public Guid GetUser_UID()
{ {
if (_user == null) if (_user == null)

View File

@ -1,10 +1,13 @@
 namespace EnotaryoPH.Web.Common.Services
namespace EnotaryoPH.Web.Common.Services
{ {
public interface ICurrentUserService public interface ICurrentUserService
{ {
string? GetEmail(); string? GetEmail();
string? GetRole();
Guid GetUser_UID(); Guid GetUser_UID();
bool IsAuthenticated(); bool IsAuthenticated();
} }
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>

View File

@ -1,21 +1,27 @@
using EnotaryoPH.Data; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EnotaryoPH.Web.Pages namespace EnotaryoPH.Web.Pages
{ {
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
private readonly ILogger<IndexModel> _logger; private readonly ICurrentUserService _currentUserService;
private readonly NotaryoDBContext _notaryoDBContext;
public IndexModel(ILogger<IndexModel> logger, NotaryoDBContext notaryoDBContext) public IndexModel(ICurrentUserService currentUserService) => _currentUserService = currentUserService;
public IActionResult OnGet()
{ {
_logger = logger; if (_currentUserService.IsAuthenticated() == false)
_notaryoDBContext = notaryoDBContext; {
return Page();
} }
public void OnGet() if (_currentUserService.GetRole() == "Principal")
{ {
return RedirectToPage("/Principal/Dashboard/Dashboard");
}
return Page();
} }
} }
} }