public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (!result.Succeeded)
{
return GetErrorResult(result);
}
else
{
// Generate the Email Confirmation Token
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// UrlEncode the token
code = HttpUtility.UrlEncode(code);
// Get the Host from the appSettings. http://www.myclientsite.com
string clientSite = AppSettingsConfig.ClientSite;
// Build the Url that will be used for the link in the email message.
var callbackUrl = clientSite + "/#/confirmemail?userId=" + user.Id + "&code=" + code;
// Build the callback message for the email.
var callbackMessage = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>";
// Send the email. Remember to set the system.net/mailSettings/smtp/network configuration in the web.config.
await UserManager.SendEmailAsync(user.Id, "Confirm your account", callbackMessage);
}
return Ok();
}