public async Task <IActionResult> LoginAdminAsync(LoginAdminViewModel inputModel, string returnUrl) { returnUrl = returnUrl ?? this.Url.Content("~/"); if (this.ModelState.IsValid) { var result = await this.signInManager.PasswordSignInAsync(inputModel.Username, inputModel.Password, inputModel.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { this.logger.LogInformation("User logged in."); return(this.LocalRedirect(returnUrl)); } if (result.IsLockedOut) { this.logger.LogWarning("User account locked out."); return(this.RedirectToPage("./Lockout")); } else { this.ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(this.View(inputModel)); } } return(this.View()); }
//[ValidateAntiForgeryToken] public async Task <JsonResult> LoginAdmin(LoginAdminViewModel model) { ApplicationDbContext app = new ApplicationDbContext(); object obj = null; ModelState.Remove("RememberMe"); ModelState.Remove("Email"); var usermanager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(app)); var user = await usermanager.FindByIdAsync(User.Identity.GetUserId()); model.Email = user.Email; if (!ModelState.IsValid) { obj = new { Success = "false", Error = "¡Ups! Hubo un error inesperado." }; return(Json(obj, JsonRequestBehavior.AllowGet)); } // No cuenta los errores de inicio de sesión para el bloqueo de la cuenta // Para permitir que los errores de contraseña desencadenen el bloqueo de la cuenta, cambie a shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, true, shouldLockout : false); switch (result) { case SignInStatus.Success: obj = new { Success = "true", Error = string.Empty }; return(Json(obj, JsonRequestBehavior.AllowGet)); case SignInStatus.Failure: default: obj = new { Success = "false", Error = "Intento de inicio de sesión no válido." }; return(Json(obj, JsonRequestBehavior.AllowGet)); } }
public ActionResult Index(LoginAdminViewModel model, string returnUrl) { try { if (!ModelState.IsValid) { return(View(model)); } var result = _loginBusiness.UserLoginAdmin(model.UserName, model.Password); if (result != null) { new Security().UserSignIn(result, System.Web.HttpContext.Current); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", @"Tên đăng nhập hoặc mật khẩu không hợp lệ."); return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", @"Đã có lỗi xảy ra khi đăng nhập. Vui lòng thử lại. Lỗi: " + ex.Message); return(View()); } }
public async Task <IActionResult> Login(LoginAdminViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var adminResto = _adminRestoRepository.Login(viewModel.LoginAdmin, viewModel.PasswordAdmin); if (adminResto == null) { ModelState.AddModelError(nameof(LoginAdminViewModel.LoginAdmin), "Не правильный логин или пароль"); return(View(viewModel)); } var pages = new List <Claim>() { new Claim("AdminResto", adminResto.LoginAdmin.ToString()), }; var claimsIdenity = AdminRestoService.GetClaimsIdentity(Startup.AuthAdminR); // !(claimsIdenity.AuthenticationType is null) && claimsIdenity.AuthenticationType == Startup.AuthAdminR if (!(claimsIdenity is null) && !string.IsNullOrEmpty(claimsIdenity.AuthenticationType) && claimsIdenity.AuthenticationType == Startup.AuthAdminR) { claimsIdenity.AddClaims(pages); }
public Login() { InitializeComponent(); ViewModel = new LoginAdminViewModel() { WindowClose = Close, WindowHide = Hide }; this.DataContext = ViewModel; }
public bool Login(LoginAdminViewModel model) { var result = db.tbl_Admin.Where(m => m.AdminName == model.AdminName && m.AdminPass == model.AdminPass).Count(); if (result > 0) { return(true); } else { return(false); } }
public IActionResult Login(LoginAdminViewModel loginViewModel) { if (ModelState.IsValid) { var result = _signInManager.PasswordSignInAsync(loginViewModel.UserName, loginViewModel.Password, loginViewModel.RememberMe, false).Result; if (result.Succeeded) { return(RedirectToAction("Index", "Admin")); } ModelState.AddModelError("", "Login hatası"); } return(View(loginViewModel)); }
public ActionResult Login(LoginAdminViewModel model) { if (model.UserName == "admin" && model.Password == "29152916") { var employeeModel = new EmployeeModel { Name = "admin", Code = "admin" }; //CustomIdentity identity = new CustomIdentity(employeeModel); //CustomPrincipal principal = new CustomPrincipal(identity); //HttpContext.User = principal; var identity = UserService.CreateIdentity(employeeModel, DefaultAuthenticationTypes.ApplicationCookie); HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, identity); return(RedirectToAction("Index")); } return(View("Login")); }
public ActionResult Login(LoginAdminViewModel model) { if (ModelState.IsValid) { if (accDAL.Login(model)) { Session.Add("ADMIN_NAME", model.AdminName); Session.Add("ADMIN_ID", model.AdminID); TempData["Admin"] = model.AdminName.ToString(); FormsAuthentication.SetAuthCookie(model.AdminName, false); return(RedirectToAction("Index", "Home", new { Area = "Admin" })); } else { ModelState.AddModelError("", "Tài khoản hoặc mật khẩu không đúng!"); } } return(View()); }
public async Task <ActionResult> Admin(LoginAdminViewModel model, string returnUrl) { // Lets first check if the Model is valid or not if (!ModelState.IsValid) { return(View(model)); } //await _serverUserCollection.GetUserTokenAsync(model.Username, model.Password); AdminUser serviceuser = await _adminUserCollection.Login(model.Username, model.Password); //ServiceUser serviceuser = serverUserCollection.Login(model.Email, model.Password); if (serviceuser == null) { ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); } //INFO: Claims are use to specify properties of an Identity(a user) List <Claim> claims = new List <Claim>(); if ((serviceuser != null)) { claims = new List <Claim> { new Claim("Name", serviceuser.Name), new Claim("Role", Role.Admin.ToString()), new Claim("Email", serviceuser.Mail), new Claim(ClaimTypes.Role, Role.Admin) }; } // var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties(); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToAction("Index", "Home")); }
public ActionResult Login() { LoginAdminViewModel model = new LoginAdminViewModel(); return(View("Login", model)); }