public ActionResult Login(LoginVM logData)
        {
            if (repo.CheckLogin(logData) || (logData.帳號 == "admin" && logData.密碼 == "admin"))
            {
                string Level = "0";
                if (logData.帳號 == "admin")
                {
                    Level = "1";
                }

                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, logData.帳號, DateTime.Now, DateTime.Now.AddMinutes(30), true,
                                                                                 Level, FormsAuthentication.FormsCookiePath);
                string encTicket = FormsAuthentication.Encrypt(ticket);
                var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                cookie.HttpOnly = true;
                Response.Cookies.Add(cookie);
            }
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        private bool CheckLogin(string account, string password)
        {
            string customId;
            string role;

            repo客戶資料.CheckLogin(account, password, out customId, out role);

            UserData = role;
            CustomId = customId;

            if (string.IsNullOrEmpty(customId))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }