You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace Estsh.Core.Controllers
{
public class BaseController : Controller
{
public SysEmp CurrentEmp;
public override void OnActionExecuting(ActionExecutingContext context)
{
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
//匿名访问不需要token认证、签名和登录
var allowanyone = controllerActionDescriptor.MethodInfo.GetCustomAttribute(typeof(AllowAnonymousAttribute), true);
if (allowanyone != null)
{
return;
}
CommonResult result = new CommonResult();
string? sessionUser = HttpContext.Session.GetString("loginedUser");
if (string.IsNullOrEmpty(sessionUser))
{
//result.message = "没有登录!";
//context.Result = Content(JsonSerializer.Serialize(result));
context.Result = Redirect("/System/Login");
return;
}
var user = JsonSerializer.Deserialize<SysEmp>(sessionUser);
if (user == null)
{
//result.message = "登录用户无效!";
//context.Result = Content(JsonSerializer.Serialize(result));
context.Result = Redirect("/System/Login");
return;
}
CurrentEmp = user;
// base.OnActionExecuting(context);
}
}
}