public async Task <IActionResult> Register([FromBody] RegisterRequest request) { var user = new ShopUser { UserName = request.Username, Email = request.Username }; var result = await _userManager.CreateAsync(user, request.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _userManager.AddToRoleAsync(user, UserRole.User.ToString()); var code = EncodeHelper.Base64Encode(await _userManager.GenerateEmailConfirmationTokenAsync(user)); var confirmationLink = UrlExtensions.EmailConfirmationLink(user.Id, code, _configuration["RedirectDomain"]); await _emailSender.SendConfirmationEmailAsync(request.Username, confirmationLink); _logger.LogInformation($"Confirmation email was sent to user: {user.Name}"); return(StatusCode((int)HttpStatusCode.NoContent)); } var errorResponse = new ErrorResponse(ErrorReasons.BadRequest, result.Errors.Select(e => e.Description).FirstOrDefault()); return(StatusCode((int)HttpStatusCode.BadRequest, errorResponse)); }