예제 #1
0
        public ActionResult LogOn(LogOnViewModel model, string returnURL)
        {
            Session.Clear();
            SessionHandler.IsMaster = false;
            if (!ValidateLogOn(model.UserName, model.Password))
            {
                //ModelState.AddModelError("LoginStatus", "Incorrect username or password.");

                model.LoginStatus = "Incorrect username or password.";

                return(View("LogOn", model));
            }

            var dealer      = new DealershipViewModel();
            var dealerGroup = new DealerGroupViewModel();
            var user        = new UserRoleViewModel();
            var checkUser   = SQLHelper.CheckUserExistWithStatus(model.UserName, model.Password);

            if (!checkUser.UserExist)
            {
                model.LoginStatus = "Incorrect username or password.";

                return(View("LogOn", model));
            }

            SessionHandler.Single = true;

            if (checkUser.MasterLogin)
            {
                SessionHandler.IsMaster = true;

                SQLHelper.MasterLogin(checkUser, ref dealerGroup, ref dealer, ref user);

                Session["CurrentUser"] = user;

                Session["Dealership"] = dealer;

                Session["DealershipName"] = dealer.DealershipName;

                Session["DealerGroup"] = dealerGroup;

                FormsAuth.SignIn(model.UserName, true);

                return(AfterLoggingOn(checkUser.Role));
            }

            if (checkUser.MultipleDealerLogin)
            {
                SQLHelper.LoginMultipleStore(checkUser, ref dealerGroup, ref dealer, ref user);

                Session["CurrentUser"] = user;

                Session["Dealership"] = dealer;

                Session["DealershipName"] = dealer.DealershipName;

                Session["DealerGroup"] = dealerGroup;

                if (checkUser.CanSeeAllStores)
                {
                    SessionHandler.Single = false;
                }

                FormsAuth.SignIn(model.UserName, true);

                return(AfterLoggingOn(checkUser.Role));
            }

            SQLHelper.LoginSingleStore(checkUser, ref dealer, ref user);

            Session["CurrentUser"] = user;

            Session["Dealership"] = dealer;

            Session["DealershipName"] = dealer.DealershipName;

            FormsAuth.SignIn(model.UserName, true);

            return(AfterLoggingOn(checkUser.Role));
        }
예제 #2
0
        public string LogOnForTimeOut(LogOnViewModel model)
        {
            Session.Clear();
            SessionHandler.IsMaster = false;

            try
            {
                var dealer      = new DealershipViewModel();
                var dealerGroup = new DealerGroupViewModel();
                var user        = new UserRoleViewModel();
                var checkUser   = SQLHelper.CheckUserExistWithStatus(model.UserName, model.Password);

                if (!checkUser.UserExist)
                {
                    return("Incorrect");
                }

                SessionHandler.Single = true;

                if (checkUser.MasterLogin)
                {
                    SessionHandler.IsMaster = true;
                    SQLHelper.MasterLogin(checkUser, ref dealerGroup, ref dealer, ref user);

                    Session["CurrentUser"] = user;

                    Session["Dealership"] = dealer;

                    Session["DealershipName"] = dealer.DealershipName;

                    Session["DealerGroup"] = dealerGroup;

                    FormsAuth.SignIn(model.UserName, true);

                    Session["HasAdminRight"] = (checkUser.Role.ToLower().Equals("king") || checkUser.Role.ToLower().Equals("admin")) ? true : false;
                    Session["IsEmployee"]    = (!checkUser.Role.ToLower().Equals("king") && !checkUser.Role.ToLower().Equals("admin") && !checkUser.Role.ToLower().Equals("manager")) ? true : false;
                    //return AfterLoggingOn(checkUser.Role);
                    return(checkUser.Role);
                }

                if (checkUser.MultipleDealerLogin)
                {
                    SQLHelper.LoginMultipleStore(checkUser, ref dealerGroup, ref dealer, ref user);

                    Session["CurrentUser"] = user;

                    Session["Dealership"] = dealer;

                    Session["DealershipName"] = dealer.DealershipName;

                    Session["DealerGroup"] = dealerGroup;

                    if (checkUser.CanSeeAllStores)
                    {
                        SessionHandler.Single = false;
                    }

                    FormsAuth.SignIn(model.UserName, true);

                    Session["HasAdminRight"] = (checkUser.Role.ToLower().Equals("king") || checkUser.Role.ToLower().Equals("admin")) ? true : false;
                    Session["IsEmployee"]    = (!checkUser.Role.ToLower().Equals("king") && !checkUser.Role.ToLower().Equals("admin") && !checkUser.Role.ToLower().Equals("manager")) ? true : false;
                    //return AfterLoggingOn(checkUser.Role);
                    return(checkUser.Role);
                }

                SQLHelper.LoginSingleStore(checkUser, ref dealer, ref user);

                Session["CurrentUser"] = user;

                Session["Dealership"] = dealer;

                Session["DealershipName"] = dealer.DealershipName;

                FormsAuth.SignIn(model.UserName, true);

                Session["HasAdminRight"] = (checkUser.Role.ToLower().Equals("king") || checkUser.Role.ToLower().Equals("admin")) ? true : false;
                Session["IsEmployee"]    = (!checkUser.Role.ToLower().Equals("king") && !checkUser.Role.ToLower().Equals("admin") && !checkUser.Role.ToLower().Equals("manager")) ? true : false;
                //return AfterLoggingOn(checkUser.Role);
                return(checkUser.Role);
            }
            catch (Exception)
            {
                return("Error");
            }
        }