Ejemplo n.º 1
0
        public ActionResult Login(string returnUrl, FR.Domain.Model.Entities.ShoppingCart cart, bool backFromCheckout = false)
        {
            ViewBag.bagitems = GetCartItems(cart);

            if (returnUrl == Url.Content("~/RestaurantOwners"))
            {
                ViewBag.OwnerLogon = "Note: Restaurant Owners only use this local login form to log in.";
            }
            else
            {
                ViewBag.OwnerLogon = "";
            }
            if (backFromCheckout && string.IsNullOrEmpty(returnUrl) == false && User.Identity.IsAuthenticated)
            {
                return(RedirectToLocal(returnUrl));
            }
            ViewBag.Groupcheckout = "n";
            ViewBag.Guest         = "yes";
            if (cart == null)
            {
                ViewBag.Guest = "no";
            }
            else
            {
                if (string.IsNullOrEmpty(cart.CartKey) == false && string.IsNullOrEmpty(cart.PersonName) == false && cart.PersonName == cart.BossName)
                {
                    ViewBag.Groupcheckout = "y";
                }
                else
                {
                    bool b = cart.BizId == 0 ? true : (cart.IsBizDelivery == false && cart.IsDelivery);
                    if (cart.Lines.Sum(x => x.Quantity) == 0 || (cart.OrderMinimum > cart.SubTotal() && cart.IsDelivery) || b)
                    {
                        ViewBag.Guest = "no";
                    }
                }
            }
            ViewBag.ReturnUrl = returnUrl;
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, FR.Domain.Model.Entities.ShoppingCart cart)
        {
            ViewBag.bagitems = GetCartItems(cart);
            if (!ModelState.IsValid)
            {
                ViewBag.Guest = "yes";
                if (cart == null)
                {
                    ViewBag.Guest = "no";
                }
                else
                {
                    bool b = cart.BizId == 0 ? true : (cart.IsBizDelivery == false && cart.IsDelivery);
                    if (cart.Lines.Sum(x => x.Quantity) == 0 || (cart.OrderMinimum > cart.SubTotal() && cart.IsDelivery) || b)
                    {
                        ViewBag.Guest = "no";
                    }
                }
                if (returnUrl == Url.Content("~/RestaurantOwners"))
                {
                    ViewBag.OwnerLogon = "Note: Restaurant Owners only use this local login form to log in.";
                }
                else
                {
                    ViewBag.OwnerLogon = "";
                }
                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
                ViewBag.ReturnUrl = returnUrl;
                return(View(model));
            }
            // find user by username first
            var user = await UserManager.FindByNameAsync(model.Email);

            var message = string.Format("Your account has been locked out for {0} minutes due to multiple failed login attempts.", ConfigurationManager.AppSettings["DefaultAccountLockoutTimeSpan"].ToString());

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : true);

            switch (result)
            {
            case SignInStatus.Success:
                await UserManager.ResetAccessFailedCountAsync(user.Id);

                UserManager.SetLockoutEnabled(user.Id, !UserManager.IsInRole(user.Id, "Admin"));
                if (UserManager.IsInRole(user.Id, "Admin"))
                {
                    return(RedirectToLocal("/Admin"));
                }
                if (UserManager.IsInRole(user.Id, "Manager"))
                {
                    return(RedirectToLocal("/FRManager"));
                }
                if (UserManager.IsInRole(user.Id, "Restaurant"))
                {
                    return(RedirectToLocal("/RestaurantOwners"));
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                ModelState.AddModelError("", message);
                return(View(model));

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

            default:
                ViewBag.Guest = "yes";
                if (cart == null)
                {
                    ViewBag.Guest = "no";
                }
                else
                {
                    bool b = cart.BizId == 0 ? true : (cart.IsBizDelivery == false && cart.IsDelivery);
                    if (cart.Lines.Sum(x => x.Quantity) == 0 || (cart.OrderMinimum > cart.SubTotal() && cart.IsDelivery) || b)
                    {
                        ViewBag.Guest = "no";
                    }
                }
                if (returnUrl == Url.Content("~/RestaurantOwners"))
                {
                    ViewBag.OwnerLogon = "Note: Restaurant Owners only use this local login form to log in.";
                }
                else
                {
                    ViewBag.OwnerLogon = "";
                }
                // If we got this far, something failed, redisplay form
                ViewBag.ReturnUrl = returnUrl;
                ModelState.AddModelError("", "Invalid login.");
                return(View(model));
            }
        }