-
-
Save chrismoutray/8a8e5f6a7b433571613b to your computer and use it in GitHub Desktop.
Example confirm signup - but how to auto signin the confirmed user???
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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