public async Task<JsonResult> CheckUsernameExists(ExternalLoginConfirmationViewModel extLoginConfViewModel) { var user = await UserManager.FindByNameAsync(extLoginConfViewModel.DefaultUserName); if (user != null) { return Json(new {exists = true}); } else { return Json(new {exists = false}); } }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { ViewBag.Information = "You have logged in successfully."; if (User.Identity.IsAuthenticated) { Session[SessionVariables.Menu] = null; return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new ApplicationUser { UserName = model.DefaultUserName, Email = model.Email, DateOfBirth = model.DateOfBirth }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }