public async Task<IHttpActionResult> RegisterExternal() { if (!ModelState.IsValid) { return BadRequest(ModelState); } var info = await AuthenticationManager_GetExternalLoginInfoAsync_WithExternalBearer(); if (info == null) { return InternalServerError(); } ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity); var user = new ApplicationUser() { Email = externalLogin.UserName, UserName = externalLogin.UserName, FirstName = externalLogin.FirstName, LastName = externalLogin.LastName }; IdentityResult result = await UserManager.CreateAsync(user); if (!result.Succeeded) { return GetErrorResult(result); } result = await UserManager.AddLoginAsync(user.Id, info.Login); if (!result.Succeeded) { 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, FirstName = model.FirstName, LastName = model.LastName }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return GetErrorResult(result); } UpdateInvitationStatusForNewUser(model.Email); return Ok(new { Message = "Registration successful." }); }