mirror of
https://github.com/guilhermewerner/gerencia-projetos
synced 2025-06-16 15:05:39 +00:00
Acho q acabou
This commit is contained in:
38
GerenciaProjetos/Filters/LoginFilterAttribute.cs
Normal file
38
GerenciaProjetos/Filters/LoginFilterAttribute.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GerenciaProjetos.Filters
|
||||
{
|
||||
public class LoginFilterAttribute : Attribute, IActionFilter
|
||||
{
|
||||
public bool Restrito { get; set; }
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
int? IdUsuario = context.HttpContext.Session.GetInt32("Id");
|
||||
|
||||
if (IdUsuario == null)
|
||||
{
|
||||
context.Result = new RedirectToRouteResult(new { controller = "Home", action = "Index" });
|
||||
}
|
||||
else if (context.HttpContext.Session.GetInt32("EAdmin") != 1 && Restrito)
|
||||
{
|
||||
context.Result = new RedirectToRouteResult(new
|
||||
{
|
||||
controller = "Dashboard",
|
||||
action = "Index"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user