This commit is contained in:
pavelbannov 2022-12-21 12:38:47 +03:00
parent 7ed3c13465
commit a1daacb4d0
3 changed files with 19 additions and 13 deletions

View File

@ -38,19 +38,19 @@ public class RedisCacheNotify<T> : ICacheNotify<T> where T : IMessage<T>, new()
public void Publish(T obj, CacheNotifyAction action)
{
Task.Run(() => _redis.PublishAsync(GetChannelName(action), new RedisCachePubSubItem<T>() { Object = obj, Action = action }))
Task.Run(async () => await _redis.PublishAsync(GetChannelName(action), new RedisCachePubSubItem<T>() { Object = obj, Action = action }))
.GetAwaiter()
.GetResult();
}
public async Task PublishAsync(T obj, CacheNotifyAction action)
{
await Task.Run(() => _redis.PublishAsync(GetChannelName(action), new RedisCachePubSubItem<T>() { Object = obj, Action = action }));
await Task.Run(async () => await _redis.PublishAsync(GetChannelName(action), new RedisCachePubSubItem<T>() { Object = obj, Action = action }));
}
public void Subscribe(Action<T> onchange, CacheNotifyAction action)
{
Task.Run(() => _redis.SubscribeAsync<RedisCachePubSubItem<T>>(GetChannelName(action), (i) =>
Task.Run(async () => await _redis.SubscribeAsync<RedisCachePubSubItem<T>>(GetChannelName(action), (i) =>
{
onchange(i.Object);
@ -61,7 +61,7 @@ public class RedisCacheNotify<T> : ICacheNotify<T> where T : IMessage<T>, new()
public void Unsubscribe(CacheNotifyAction action)
{
Task.Run(() => _redis.UnsubscribeAsync<RedisCachePubSubItem<T>>(GetChannelName(action), (i) =>
Task.Run(async () => await _redis.UnsubscribeAsync<RedisCachePubSubItem<T>>(GetChannelName(action), (i) =>
{
return Task.FromResult(true);
})).GetAwaiter()

View File

@ -254,7 +254,7 @@ public class TariffService : ITariffService
}
}
if (tariffId.HasValue)
if (tariffId.HasValue && tariffId.Value != 0)
{
_notify.Publish(new TariffCacheItem { TenantId = tenantId, TariffId = tariffId.Value }, CacheNotifyAction.Insert);
}

View File

@ -68,7 +68,8 @@ public class AuthenticationController : ControllerBase
private readonly UserManagerWrapper _userManagerWrapper;
private readonly TfaAppAuthSettingsHelper _tfaAppAuthSettingsHelper;
private readonly EmailValidationKeyProvider _emailValidationKeyProvider;
private readonly BruteForceLoginManager _bruteForceLoginManager;
private readonly BruteForceLoginManager _bruteForceLoginManager;
private readonly ILogger<AuthenticationController> _logger;
public AuthenticationController(
UserManager userManager,
@ -104,7 +105,8 @@ public class AuthenticationController : ControllerBase
DbLoginEventsManager dbLoginEventsManager,
BruteForceLoginManager bruteForceLoginManager,
TfaAppAuthSettingsHelper tfaAppAuthSettingsHelper,
EmailValidationKeyProvider emailValidationKeyProvider)
EmailValidationKeyProvider emailValidationKeyProvider,
ILogger<AuthenticationController> logger)
{
_userManager = userManager;
_tenantManager = tenantManager;
@ -140,6 +142,7 @@ public class AuthenticationController : ControllerBase
_bruteForceLoginManager = bruteForceLoginManager;
_tfaAppAuthSettingsHelper = tfaAppAuthSettingsHelper;
_emailValidationKeyProvider = emailValidationKeyProvider;
_logger = logger;
}
[AllowNotPayment]
@ -197,12 +200,13 @@ public class AuthenticationController : ControllerBase
return result;
}
catch
catch (Exception ex)
{
_messageService.Send(user.DisplayUserName(false, _displayUserSettingsHelper), sms
? MessageAction.LoginFailViaApiSms
: MessageAction.LoginFailViaApiTfa,
_messageTarget.Create(user.Id));
_messageTarget.Create(user.Id));
_logger.ErrorWithException(ex);
throw new AuthenticationException("User authentication failed");
}
finally
@ -279,9 +283,10 @@ public class AuthenticationController : ControllerBase
Expires = new ApiDateTime(_tenantManager, _timeZoneConverter, expires)
};
}
catch
catch (Exception ex)
{
_messageService.Send(user.DisplayUserName(false, _displayUserSettingsHelper), viaEmail ? MessageAction.LoginFailViaApi : MessageAction.LoginFailViaApiSocialAccount);
_messageService.Send(user.DisplayUserName(false, _displayUserSettingsHelper), viaEmail ? MessageAction.LoginFailViaApi : MessageAction.LoginFailViaApiSocialAccount);
_logger.ErrorWithException(ex);
throw new AuthenticationException("User authentication failed");
}
finally
@ -437,9 +442,10 @@ public class AuthenticationController : ControllerBase
_messageService.Send(!string.IsNullOrEmpty(inDto.UserName) ? inDto.UserName : AuditResource.EmailNotSpecified, MessageAction.LoginFailBruteForce);
throw new AuthenticationException("Login Fail. Too many attempts");
}
catch
catch (Exception ex)
{
_messageService.Send(!string.IsNullOrEmpty(inDto.UserName) ? inDto.UserName : AuditResource.EmailNotSpecified, action);
_messageService.Send(!string.IsNullOrEmpty(inDto.UserName) ? inDto.UserName : AuditResource.EmailNotSpecified, action);
_logger.ErrorWithException(ex);
throw new AuthenticationException("User authentication failed");
}
wrapper.UserInfo = user;