public async Task <IActionResult> SignUp(SignUpViewModel signUpViewModel) { if (ModelState.IsValid && signUpViewModel.AgreeTerms) { try { // new datadock identity inc claim var datadockIdentity = new ClaimsIdentity(); datadockIdentity.AddClaim(new Claim(DataDockClaimTypes.DataDockUserId, User.Identity.Name)); User.AddIdentity(datadockIdentity); // create user in datadock var newUser = await _userStore.CreateUserAsync(User.Identity.Name, User.Claims); if (newUser == null) { Log.Error("Creation of new user account returned null"); return(RedirectToAction("Error", "Home")); } // create userSettings var userSettings = new UserSettings { UserId = User.Identity.Name, LastModified = DateTime.UtcNow, LastModifiedBy = "DataDock" }; await _userStore.CreateOrUpdateUserSettingsAsync(userSettings); // create ownerSettings for the github user owner var userOwner = new OwnerSettings { OwnerId = User.Identity.Name, IsOrg = false, DisplayGitHubAvatar = true, DisplayGitHubDescription = true, LastModified = DateTime.UtcNow, LastModifiedBy = "DataDock" }; await _ownerSettingsStore.CreateOrUpdateOwnerSettingsAsync(userOwner); // logout and back in to persist new claims await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return(Challenge(new AuthenticationProperties() { RedirectUri = "account/welcome" })); } catch (UserAccountExistsException) { Log.Warning("User account {0} already exists. Identities: {1}. Claims Total: {2}", User.Identity.Name, User.Identities.Count(), User.Claims.Count()); var datadockUser = await _userStore.GetUserAccountAsync(User.Identity.Name); if (datadockUser.Claims.FirstOrDefault(c => c.Type.Equals(DataDockClaimTypes.DataDockUserId)) == null) { // new datadock identity inc claim var datadockIdentity = new ClaimsIdentity(); datadockIdentity.AddClaim(new Claim(DataDockClaimTypes.DataDockUserId, User.Identity.Name)); User.AddIdentity(datadockIdentity); await _userStore.UpdateUserAsync(User.Identity.Name, User.Claims); // logout and back in to persist new claims await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return(Challenge(new AuthenticationProperties() { RedirectUri = "account/settings" })); } return(RedirectToAction("Settings")); } catch (Exception ex) { Log.Error("Error creating user account", ex); Console.WriteLine(ex); throw; } } ViewBag.Success = "failed"; return(View(signUpViewModel)); }