/// <inheritdoc /> public async Task CreateDevice(UserDevice device) { GuardDevice(device); _dbContext.UserDevices.Add(device); await _dbContext.SaveChangesAsync(); var user = device.User; if (user == null) { user = await _dbContext.Users.SingleOrDefaultAsync(x => x.Id == device.UserId); } var @event = new DeviceCreatedEvent(DeviceInfo.FromUserDevice(device), SingleUserInfo.FromUser(user)); await _eventService.Publish(@event); }
/// <inheritdoc /> public override async Task <IdentityResult> AccessFailedAsync(TUser user) { var result = await base.AccessFailedAsync(user); if (await IsLockedOutAsync(user)) { var @event = new AccountLockedEvent(SingleUserInfo.FromUser(user)); await _eventService.Publish(@event); } return(result); }
public async Task <IActionResult> ConfirmEmail([FromBody] ConfirmEmailRequest request) { var userId = User.FindFirstValue(JwtClaimTypes.Subject); var user = await _userManager.Users.Include(x => x.Claims).Where(x => x.Id == userId).SingleOrDefaultAsync(); if (user == null) { return(NotFound()); } if (user.EmailConfirmed) { ModelState.AddModelError(nameof(request.Token).ToLower(), _userManager.MessageDescriber.EmailAlreadyConfirmed); return(BadRequest(new ValidationProblemDetails(ModelState))); } var result = await _userManager.ConfirmEmailAsync(user, request.Token); if (!result.Succeeded) { return(BadRequest(result.Errors.ToValidationProblemDetails())); } var eventInfo = user.ToBasicUserInfo(); await _eventService.Publish(new UserEmailConfirmedEvent(eventInfo)); return(NoContent()); }