public async Task <IActionResult> Login(string returnUrl) { LogInUserViewModel model = new LogInUserViewModel { ReturnUrl = returnUrl, ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList() }; return(View(model)); }
public async Task <bool> LogIn(LogInUserViewModel userLog) { var user = this.GetUserByName(userLog.UserName).Result; if (user == null || user.ActiveOrNotActiveAccount == false) { return(false); } var result = await this.signInManager.PasswordSignInAsync(user, userLog.Password, isPersistent : false, lockoutOnFailure : false); return(result.Succeeded); }
public IActionResult LogIn(LogInUserViewModel userLogIn) { bool result = userServices.LogIn(userLogIn).Result; if (!result) { return(this.View(userLogIn)); } else { return(Redirect("/")); } }
public async Task <IActionResult> Login(LogInUserViewModel model, String ReturnUrl) { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RemmberMe, true); if (result.Succeeded) { if (ReturnUrl != null) { return(LocalRedirect(ReturnUrl)); } return(RedirectToAction("Index", "Home")); } ModelState.AddModelError(string.Empty, "invaild"); } return(View()); }
public JsonResult LogIn(LogInUserViewModel logInUserViewModel) { if (!ModelState.IsValid) { return(Json(new { success = false, message = Constants.ErrorMessage })); } var password = AuthorizationHelper.GetHashString(logInUserViewModel.Password); var user = _userService.CheckUserExists(logInUserViewModel.UserId, password); if (user == null) { return(Json(new { success = false, message = "Неправильный пароль!" })); } FormsAuthentication.SetAuthCookie(user.Name, logInUserViewModel.RememberMe); GlobalStoreHelper.SetSession(user); return(Json(new { success = true, nextPage = Url.Action("Index", "Home") }, JsonRequestBehavior.AllowGet)); }
public IActionResult LogIn(LogInUserViewModel u) { if (ModelState.IsValid) { try { if (repo.GetPassword(u.Username) == u.Password) { HttpContext.Session.SetString("Account", u.Username); return(RedirectToAction("Index", "Home")); } } catch (Exception) { return(View("Error")); } } u.Password = ""; return(View(u)); }
public async Task <IActionResult> Login(LogInUserViewModel model, string returnUrl) { model.ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(model.Email); if (user != null && !user.EmailConfirmed && (await userManager.CheckPasswordAsync(user, model.Password))) { ModelState.AddModelError(string.Empty, "Email not confirmed yet." + " Please check your inbox for a confirmation email and click the link inside."); return(View(model)); } var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, true); if (result.Succeeded) { if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } if (result.IsLockedOut) { return(View("AccountLocked")); } ModelState.AddModelError(string.Empty, "Invalid Login details"); } return(View(model)); }
public async Task <HttpStatusCode> LogInAsync(LogInUserViewModel viewModel) { const string logInAsyncUri = ""; return(await _httpService.UpdateEntityAsync(viewModel, logInAsyncUri)); }
public async Task <IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null) { returnUrl = returnUrl ?? Url.Content("~/"); LogInUserViewModel loginViewModel = new LogInUserViewModel { ReturnUrl = returnUrl, ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList() }; if (remoteError != null) { ModelState.AddModelError(string.Empty, $"Error from external provider: {remoteError}"); return(View("Login", loginViewModel)); } var info = await signInManager.GetExternalLoginInfoAsync(); if (info == null) { ModelState.AddModelError(string.Empty, $"Error loading external login information"); return(View("Login", loginViewModel)); } var email = info.Principal.FindFirstValue(ClaimTypes.Email); ApplicationUser user = null; if (email != null) { user = await userManager.FindByEmailAsync(email); if (user != null && !user.EmailConfirmed) { ModelState.AddModelError(string.Empty, "Email not confirmed yet." + " Please check your inbox for a confirmation email and click the link inside."); return(View("Login", loginViewModel)); } } var signInResult = await signInManager.ExternalLoginSignInAsync( info.LoginProvider, info.ProviderKey, isPersistent : false, bypassTwoFactor : true); if (signInResult.Succeeded) { return(LocalRedirect(returnUrl)); } else { if (email != null) { if (user == null) { user = new ApplicationUser { UserName = info.Principal.FindFirstValue(ClaimTypes.Email), Email = info.Principal.FindFirstValue(ClaimTypes.Email) }; await userManager.CreateAsync(user); //give users role to new user await userManager.AddToRoleAsync(user, "Users"); var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); logger.Log(LogLevel.Warning, confirmationLink); ViewBag.ErrorTitle = "Registration Succesfull"; ViewBag.ErrorMessage = "Before you can login, please confirm your email, " + " by clicking on the confirmation link we have emailed you."; return(View("Error")); } await userManager.AddLoginAsync(user, info); await signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } ViewBag.ErrorTitle = $"Email claim not received from: {info.LoginProvider}"; ViewBag.ErrorMessage = "Please contact support on [email protected]"; return(View("Error")); } }