Ejemplo n.º 1
0
        public ActionResult Login(LoginModel model)
        {
            CustSecurityController Secure = new CustSecurityController();
            WebSecurity.Logout();

            //IP Check
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                if (Roles.IsUserInRole(model.UserName, "Admin"))
                {
                    if (CustSecurity.IPCheck(Secure.Details(model.UserName), Request.UserHostAddress))
                    {
                        return RedirectToAction("Index", "Dashboard");
                    }
                    else
                    {
                        WebSecurity.Logout();
                        Secure.createIPVerification(new IPProfile(model.UserName, Request.UserHostAddress));
                        ModelState.AddModelError("", "IP is not certified, an email has been sent to your account");
                        return View("~/Views/Account/Login.aspx", model);
                    }
                }

                // If we got this far, admin login failed, so you are just regular user
                return RedirectToAction("Overview", "Page");
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View("~/Views/Account/Login.aspx", model);
        }