private async Task <RVTUser> AutoProvisionUser(string provider, string providerUserId, IEnumerable <Claim> claims) { var user = new RVTUser(); await _signinManager.UserManager.CreateAsync(user); // add external user ID to new account await _signinManager.UserManager.AddLoginAsync(user, new UserLoginInfo(provider, providerUserId, provider)); return(user); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View()); } if (_userManager.FindByEmailAsync(model.Email).Result != null || _userManager.FindByNameAsync(model.Username).Result != null) { ModelState.AddModelError(string.Empty, "Username or password arleady in use"); return(View()); } var rVTUser = new RVTUser() { UserName = model.Username, PasswordHash = model.Password.ToSha256(), Email = model.Email, PhoneNumber = model.PhoneNumber, RegisterTimeStamp = DateTime.Now, EmailConfirmed = true, // for the moment PhoneNumberConfirmed = true, // for the moment }; var result = _userManager.CreateAsync(rVTUser, model.Password.ToSha256()).Result; var user = _signInManager.UserManager.FindByEmailAsync(rVTUser.Email).Result; await _userManager.AddClaimAsync(user, new Claim(JwtClaimTypes.FamilyName, model.LastName)); await _userManager.AddClaimAsync(user, new Claim(JwtClaimTypes.Name, model.FirstName)); await _userManager.AddToRoleAsync(user, "User"); return(RedirectToAction("Login", "Account")); }