public async Task <double> DistanceTo([FromBody] GeoCoordinateViewModel geoCoordinateViewModel) { var userId = this.User.FindFirstValue("UserId"); var result = geoCoordinateViewModel.BaseCoordinates.DistanceTo(geoCoordinateViewModel.TargetCoordinates); var request = new AddUserLocationCommand(userId, geoCoordinateViewModel.BaseCoordinates, geoCoordinateViewModel.TargetCoordinates); await _mediatR.Send(request); return(result); }
public async Task <ActionResult> PostAsync( [ModelBinder(typeof(CountryModelBinder))] string country, [FromBody] LoginRequest model, [FromHeader(Name = "User-Agent")] string agent, CancellationToken token) { var user = await _userManager.FindByEmailAsync(model.Email); if (user is null) { ModelState.AddModelError(nameof(model.Password), _localizer["BadLogin"]); return(BadRequest(ModelState)); } agent = agent?.Substring(0, Math.Min(agent.Length, 255)); var command = new AddUserLocationCommand(user, country, HttpContext.GetIpAddress(), model.FingerPrint, agent); var t1 = _commandBus.DispatchAsync(command, token); var t2 = _signInManager.CheckPasswordSignInAsync(user, model.Password, true); await Task.WhenAll(t1, t2); var result = t2.Result; if (result == SignInResult.Success) { await _userManager.ResetAccessFailedCountAsync(user); await _signInManager.SignInAsync(user, false); return(Ok(new { user.Country })); } if (result.IsLockedOut) { if (user.LockoutEnd == DateTimeOffset.MaxValue) { ModelState.AddModelError(nameof(model.Password), _localizer["LockOut"]); return(BadRequest(ModelState)); } ModelState.AddModelError(nameof(model.Password), _localizer["TempLockOut"]); return(BadRequest(ModelState)); } if (result.IsNotAllowed) { ModelState.AddModelError(nameof(model.Password), _localizer["NotAllowed"]); return(BadRequest(ModelState)); } ModelState.AddModelError(nameof(model.Password), _localizer["BadLogin"]); return(BadRequest(ModelState)); }
private async Task <IActionResult> FinishRegistrationAsync(User user, string country, string fingerPrint, string userAgent, CancellationToken token) { if (TempData[HomeController.Referral] != null) { if (Base62.TryParse(TempData[HomeController.Referral].ToString(), out var base62)) { try { var command = new ReferringUserCommand(base62, user.Id); await _commandBus.DispatchAsync(command, token); } catch (UserLockoutException) { _logger.Warning($"{user.Id} got locked referring user {TempData[HomeController.Referral]}"); } } else { _logger.Error($"{user.Id} got wrong referring user {TempData[HomeController.Referral]}"); } TempData.Remove(HomeController.Referral); } TempData.Clear(); var command2 = new AddUserLocationCommand(user, country, HttpContext.GetIpAddress(), fingerPrint, userAgent); var registrationBonusCommand = new FinishRegistrationCommand(user.Id); var t1 = _commandBus.DispatchAsync(command2, token); var t2 = _signInManager.SignInAsync(user, false); var t3 = _commandBus.DispatchAsync(registrationBonusCommand, token); await Task.WhenAll(t1, t2, t3); return(Ok(new { user.Id })); }