public async Task <IActionResult> Register([FromBody] CreateUserParams userParams) { var user = new UserDto { FirstName = userParams.FirstName, LastName = userParams.LastName, Email = userParams.Email, Username = userParams.Username, }; var resultingUser = await _userEngine.CreateUser(user, userParams.Password); if (resultingUser != null) { var code = await _userEngine.GenerateEmailConfirmation(resultingUser); var link = $"{Request.Scheme}://{Request.Host}/api/auth/confirmEmail?userId={resultingUser.Id}&code={HtmlEncoder.Default.Encode(code)}"; var text = $"Confirm your account here: {link} "; await _emailEngine.SendEmail(new EmailDto { ToAddresses = new List <string> { userParams.Email }, Subject = "Verify Your Account", TextContent = text }); return(Ok()); } return(Unauthorized()); }
public async Task <IActionResult> Register([FromBody] RegisterModel model) { if (!ModelState.IsValid) { return(BadRequest(new { message = AddErrors() })); } var result = await _userEngine.CreateUser(model); if (!result.Succeeded) { return(BadRequest(new { message = result.StatusMessage })); } var clientPath = _config["clientSite"]; if (!string.IsNullOrEmpty(clientPath)) { var encodedCode = UrlEncoder.Default.Encode(HttpUtility.HtmlEncode(result.EmailCode)); var callbackUrl = $"{Request.Scheme}://{clientPath}/confirmemail?id={result.UserId}&code={encodedCode}"; await _emailSenderService.SendEmailConfirmationAsync(result.Email, callbackUrl); } return(Ok()); }