Exemplo n.º 1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

            if (model.UnitName == null)
            {
                model.UnitName = SysBaseInfor.DefaultUnit;
            }
            //if (!ModelState.IsValid)
            //{
            //    return View(model);
            //}

            UnitsDAL unitCtrl = new UnitsDAL();
            Units    unitObj  = unitCtrl.GetUnitByCode(model.UnitName);

            var result = SignInStatus.Failure;

            if ((model.UserName.ToLower() == SysBaseInfor.SuperAdmin.ToLower()) || (unitObj != null && (unitObj.Active == true)))
            {
                result = await SignInHelper.PassworCheck(unitObj, model.UserName.ToLower(), model.Password, model.RememberMe, shouldLockout : false);
            }

            switch (result)
            {
            case SignInStatus.Success:

                // gan session
                Session["userLogin"] = model.UserName;
                Session["unitLogin"] = model.UnitName;
                await OnLogin();

                return(Redirect("/"));

            //return RedirectToAction("OuthenGoogle", new { ReturnUrl = returnUrl }); bat authen qrcode

            case SignInStatus.LockedOut:
                ModelState.AddModelError("", "Tài khoản bị khóa!");
                return(View(model));

            case SignInStatus.RequiresTwoFactorAuthentication:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Sai thông tin tài khoản.");
                return(View(model));
            }
        }