Skip to content

Instantly share code, notes, and snippets.

@chrismoutray
Last active October 6, 2015 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismoutray/8a8e5f6a7b433571613b to your computer and use it in GitHub Desktop.
Save chrismoutray/8a8e5f6a7b433571613b to your computer and use it in GitHub Desktop.
Example confirm signup - but how to auto signin the confirmed user???
[AllowAnonymous]
[HttpGet]
[Route("confirm-signup", Name = "ConfirmSignUpRoute")]
public async Task<IHttpActionResult> ConfirmSignUp(string userId = "", string code = "")
{
IdentityResult confirmEmailResult = await this.AppUserManager.ConfirmEmailAsync(userId, code);
if (!confirmEmailResult.Succeeded)
{
return GetErrorResult(confirmEmailResult);
}
IdentityResult addToRolesResult = await this.AppUserManager.AddToRolesAsync(userId, new string[] { "User" });
if (!addToRolesResult.Succeeded)
{
ModelState.AddModelError("", "Failed to add user roles");
return BadRequest(ModelState);
}
// ########################################
// auto signin confirmed user
// ########################################
this.Authentication.SignOut("JWT");
ApplicationUser user = await this.AppUserManager.FindByIdAsync(userId);
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(this.AppUserManager, "JWT");
this.Authentication.SignIn(new AuthenticationProperties() { IsPersistent = true }, oAuthIdentity);
// where Authentication is a property in the base-controller
// ie Request.GetOwinContext().Authentication
Uri redirectLocation = new Uri("http://localhost:8080/#/signup-confirmed");
return Redirect(redirectLocation);
//Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id }));
//return Created(locationHeader, TheModelFactory.Create(user));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment