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? GetRole() => _user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value;
public Guid GetUser_UID()
{
if (_user == null)

View File

@ -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();
}
}

View File

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

View File

@ -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<IndexModel> _logger;
private readonly NotaryoDBContext _notaryoDBContext;
private readonly ICurrentUserService _currentUserService;
public IndexModel(ILogger<IndexModel> 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();
}
}
}