private async Task <User> GetUser(ActionExecutingContext context, int userId) { var userService = context.GetService <IUserService>(); var user = await userService.GetUserWithFullInfo(userId); return(user); }
private async Task <UserToken> GetUserToken(ActionExecutingContext context) { ////TODO: Examine this part later with team: Line 688 throws null reference exception var tokenService = context.GetService <ITokenService>(); var tokenValue = context.HttpContext.Request.GetToken(); if (tokenService != null && string.IsNullOrWhiteSpace(tokenValue) == false) { var userToken = await tokenService.GetUserToken(tokenValue); var isValid = await tokenService.ValidateToken(userToken.AuthToken, true); return(isValid ? userToken : null); } return(null); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { await next(); return; } if (!IsGlobalFeatureEnabled(context.Controller.GetType(), out var attribute)) { var logger = context.GetService <ILogger <GlobalFeatureActionFilter> >(NullLogger <GlobalFeatureActionFilter> .Instance); logger.LogWarning($"The '{context.Controller.GetType().FullName}' controller needs to enable '{attribute.Name}' feature."); context.Result = new NotFoundResult(); return; } await next(); }
/// <summary> /// 判断是否写日志 /// </summary> /// <param name="context"></param> /// <param name="auditLog"></param> /// <param name="auditLogAction"></param> /// <returns></returns> private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; var options = context.GetRequiredService <IOptions <AuditingOptions> >().Value; if (!options.IsEnabled) { return(false); } if (!context.ActionDescriptor.IsControllerAction()) { return(false); } var auditLogScope = context.GetService <IAuditingManager>()?.Current; if (auditLogScope == null) { return(false); } var auditingFactory = context.GetRequiredService <IAuditingFactory>(); if (!auditingFactory.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true)) { return(false); } auditLog = auditLogScope.Log; auditLogAction = auditingFactory.CreateAuditLogAction( auditLog, context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(), context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo, context.ActionArguments ); return(true); }