public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); // Attention - New version that processes claims // Study the RegisterBindingModel object that is passed into this method // Also, look at this text file in the root of the project: // Account-Register-request-bodies.txt // It has content that you can use in Fiddler if (result.Succeeded) { // Add claims await UserManager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Email, model.Email)); await UserManager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Role, "User")); await UserManager.AddClaimAsync(user.Id, new Claim(ClaimTypes.GivenName, model.GivenName)); await UserManager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Surname, model.Surname)); foreach (var role in model.Roles) { await UserManager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Role, role)); } } else { return GetErrorResult(result); } return Ok(); }
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); } return Ok(); }