public async Task <IActionResult> RegisterNewAccount(RegisterNewAccountViewModel model) { if (string.IsNullOrEmpty(model.UserId)) { throw new ApplicationException($"No UserId provided for registration"); } if (ModelState.IsValid) { using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var user = await _userManager.FindByIdAsync(model.UserId); if (user != null) { await _userService.LogUpdatePasswordAsync(user.Id); var result = await _userManager.ResetPasswordAsync(user, model.PasswordToken, model.NewPassword); if (result.Succeeded) { await _userService.LogOnUpdateAsync(user.Id); // Resetting the security stamp invalidates the password token so operation cannot be redone. await _userManager.UpdateSecurityStampAsync(user); await _signInManager.SignInAsync(user, true); user.NameFirst = model.NameFirst.Trim(); user.NameFamily = model.NameFamily.Trim(); user.PhoneNumber = model.PhoneWork?.Trim(); user.PhoneNumberCellphone = model.PhoneCellphone?.Trim(); user.LastLoginAt = _clock.SwedenNow; result = await _userManager.UpdateAsync(user); await _userService.LogLoginAsync(user.Id); model.IsCustomer = user.CustomerOrganisationId.HasValue; if (result.Succeeded) { _logger.LogInformation("Successfully created new user {userId}", user.Id); //when user is updated refresh sign in to get possible updated claims if (!User.IsImpersonated()) { await _signInManager.RefreshSignInAsync(user); } transaction.Complete(); return(View(nameof(RegisterNewAccountConfirmation), model)); } } } else { throw new ApplicationException($"Found no user with id {model.UserId}"); } } return(View(model)); }
public IActionResult RegisterNewAccountConfirmation(RegisterNewAccountViewModel model) { return(View(model)); }