1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-25 17:27:45 +01:00

[SG-823] Undid changes to capture device push token on login (#2427)

* Revert "Set Id property on existing devices so we don't try to create a new one instead of updating existing. (#2420)"

This reverts commit 02e4b10ae8.

* Revert "Update push token on login to allow multiple users on mobile devices (#2404)"

This reverts commit 24469e2267.

* Added back test changes.
This commit is contained in:
Todd Martin 2022-12-12 15:51:41 -05:00 committed by GitHub
parent e042360c00
commit e340cba8fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 13 deletions

View File

@ -17,6 +17,7 @@ public class DevicesController : Controller
private readonly IDeviceService _deviceService; private readonly IDeviceService _deviceService;
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
public DevicesController( public DevicesController(
IDeviceRepository deviceRepository, IDeviceRepository deviceRepository,
IDeviceService deviceService, IDeviceService deviceService,
@ -100,7 +101,6 @@ public class DevicesController : Controller
} }
await _deviceService.SaveAsync(model.ToDevice(device)); await _deviceService.SaveAsync(model.ToDevice(device));
} }
[AllowAnonymous] [AllowAnonymous]

View File

@ -7,5 +7,4 @@ public interface IDeviceService
Task SaveAsync(Device device); Task SaveAsync(Device device);
Task ClearTokenAsync(Device device); Task ClearTokenAsync(Device device);
Task DeleteAsync(Device device); Task DeleteAsync(Device device);
} }

View File

@ -41,7 +41,6 @@ public class DeviceService : IDeviceService
public async Task DeleteAsync(Device device) public async Task DeleteAsync(Device device)
{ {
await _deviceRepository.DeleteAsync(device); await _deviceRepository.DeleteAsync(device);
await _pushRegistrationService.DeleteRegistrationAsync(device.Id.ToString()); await _pushRegistrationService.DeleteRegistrationAsync(device.Id.ToString());
} }
} }

View File

@ -37,6 +37,7 @@ public abstract class BaseRequestValidator<T> where T : class
private readonly IPolicyRepository _policyRepository; private readonly IPolicyRepository _policyRepository;
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
private readonly ICaptchaValidationService _captchaValidationService; private readonly ICaptchaValidationService _captchaValidationService;
public BaseRequestValidator( public BaseRequestValidator(
UserManager<User> userManager, UserManager<User> userManager,
IDeviceRepository deviceRepository, IDeviceRepository deviceRepository,
@ -544,16 +545,19 @@ public abstract class BaseRequestValidator<T> where T : class
private async Task<Device> SaveDeviceAsync(User user, ValidatedTokenRequest request) private async Task<Device> SaveDeviceAsync(User user, ValidatedTokenRequest request)
{ {
var deviceFromRequest = GetDeviceFromRequest(request); var device = GetDeviceFromRequest(request);
if (deviceFromRequest != null) if (device != null)
{ {
var existingDevice = await GetKnownDeviceAsync(user, request); var existingDevice = await GetKnownDeviceAsync(user, request);
if (existingDevice == null) if (existingDevice == null)
{ {
device.UserId = user.Id;
await _deviceService.SaveAsync(device);
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
if (now - user.CreationDate > TimeSpan.FromMinutes(10)) 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<DisplayAttribute>()?.GetName(); .FirstOrDefault()?.GetCustomAttribute<DisplayAttribute>()?.GetName();
if (!_globalSettings.DisableEmailNewDevice) if (!_globalSettings.DisableEmailNewDevice)
{ {
@ -561,17 +565,14 @@ public abstract class BaseRequestValidator<T> where T : class
_currentContext.IpAddress); _currentContext.IpAddress);
} }
} }
}
else return device;
{
deviceFromRequest.Id = existingDevice.Id;
} }
deviceFromRequest.UserId = user.Id; return existingDevice;
await _deviceService.SaveAsync(deviceFromRequest);
} }
return deviceFromRequest; return null;
} }
private async Task ResetFailedAuthDetailsAsync(User user) private async Task ResetFailedAuthDetailsAsync(User user)