diff --git a/src/Api/Controllers/DevicesController.cs b/src/Api/Controllers/DevicesController.cs index 1e94236a30..cc4ae0f128 100644 --- a/src/Api/Controllers/DevicesController.cs +++ b/src/Api/Controllers/DevicesController.cs @@ -17,6 +17,7 @@ public class DevicesController : Controller private readonly IDeviceService _deviceService; private readonly IUserService _userService; private readonly IUserRepository _userRepository; + public DevicesController( IDeviceRepository deviceRepository, IDeviceService deviceService, @@ -100,7 +101,6 @@ public class DevicesController : Controller } await _deviceService.SaveAsync(model.ToDevice(device)); - } [AllowAnonymous] diff --git a/src/Core/Services/IDeviceService.cs b/src/Core/Services/IDeviceService.cs index 2cb441ba1c..3109cc107a 100644 --- a/src/Core/Services/IDeviceService.cs +++ b/src/Core/Services/IDeviceService.cs @@ -7,5 +7,4 @@ public interface IDeviceService Task SaveAsync(Device device); Task ClearTokenAsync(Device device); Task DeleteAsync(Device device); - } diff --git a/src/Core/Services/Implementations/DeviceService.cs b/src/Core/Services/Implementations/DeviceService.cs index 16d0937a78..99f4648a3e 100644 --- a/src/Core/Services/Implementations/DeviceService.cs +++ b/src/Core/Services/Implementations/DeviceService.cs @@ -41,7 +41,6 @@ public class DeviceService : IDeviceService public async Task DeleteAsync(Device device) { await _deviceRepository.DeleteAsync(device); - await _pushRegistrationService.DeleteRegistrationAsync(device.Id.ToString()); } } diff --git a/src/Identity/IdentityServer/BaseRequestValidator.cs b/src/Identity/IdentityServer/BaseRequestValidator.cs index f5cdb9ebb2..c7d88e9e94 100644 --- a/src/Identity/IdentityServer/BaseRequestValidator.cs +++ b/src/Identity/IdentityServer/BaseRequestValidator.cs @@ -37,6 +37,7 @@ public abstract class BaseRequestValidator where T : class private readonly IPolicyRepository _policyRepository; private readonly IUserRepository _userRepository; private readonly ICaptchaValidationService _captchaValidationService; + public BaseRequestValidator( UserManager userManager, IDeviceRepository deviceRepository, @@ -544,16 +545,19 @@ public abstract class BaseRequestValidator where T : class private async Task SaveDeviceAsync(User user, ValidatedTokenRequest request) { - var deviceFromRequest = GetDeviceFromRequest(request); - if (deviceFromRequest != null) + var device = GetDeviceFromRequest(request); + if (device != null) { var existingDevice = await GetKnownDeviceAsync(user, request); if (existingDevice == null) { + device.UserId = user.Id; + await _deviceService.SaveAsync(device); + var now = DateTime.UtcNow; if (now - user.CreationDate > TimeSpan.FromMinutes(10)) { - var deviceType = deviceFromRequest.Type.GetType().GetMember(deviceFromRequest.Type.ToString()) + var deviceType = device.Type.GetType().GetMember(device.Type.ToString()) .FirstOrDefault()?.GetCustomAttribute()?.GetName(); if (!_globalSettings.DisableEmailNewDevice) { @@ -561,17 +565,14 @@ public abstract class BaseRequestValidator where T : class _currentContext.IpAddress); } } - } - else - { - deviceFromRequest.Id = existingDevice.Id; + + return device; } - deviceFromRequest.UserId = user.Id; - await _deviceService.SaveAsync(deviceFromRequest); + return existingDevice; } - return deviceFromRequest; + return null; } private async Task ResetFailedAuthDetailsAsync(User user)