public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null) { if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await SignInManager.GetExternalLoginInfoAsync(); if (info == null) { throw new ApplicationException("Error loading external login information during confirmation."); } var user = new MaddalenaUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user, info); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false); Logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewData["ReturnUrl"] = returnUrl; return View(nameof(ExternalLogin), model); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new MaddalenaUser { UserName = model.Username, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailAsync(model.Email, callbackUrl, ""); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
private async Task LoadSharedKeyAndQrCodeUriAsync(MaddalenaUser user, EnableAuthenticatorViewModel model) { var unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await UserManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user); } model.SharedKey = FormatKey(unformattedKey); model.AuthenticatorUri = GenerateQrCodeUri(user.Email, unformattedKey); }
public async Task Register(RegisterViewModel model, string returnUrl = null) { var user = new MaddalenaUser { UserName = model.Username, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { throw new ValidationException(result.Errors); } var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); await EmailSender.SendMailConfirmationLink(user.Id, code); await SignInManager.SignInAsync(user, isPersistent: false); }
public async Task <ActionResult> Edit(MaddalenaUser user) { await _userUserCollection.UpdateAsync(user); return(Redirect("/user")); }