Ejemplo n.º 1
0
        public ActionResult SignIn(string email = "", string password = "")
        {
            password = MD5Helper.CodeMD5(password);
            UserAccount user = UserAccountBLL.Authorize(email, password, UserAccountTypes.Employee);

            if (user != null)// đăng nhập thành công
            {
                WebUserData userData = new WebUserData()
                {
                    UserID    = user.UserID,
                    FullName  = user.FullName,
                    GroupName = user.Roles, //TODO cần thay đổi cho đúng
                    LoginTime = DateTime.Now,
                    SessionID = Session.SessionID,
                    ClientIP  = Request.UserHostAddress,
                    Photo     = user.Photo,
                    Title     = user.Title
                };
                System.Web.Security.FormsAuthentication.SetAuthCookie(userData.ToCookieString(), false);
                return(RedirectToAction("Index", "Dashboard"));
            }
            else// đăng nhập không thành công
            {
                ModelState.AddModelError("LoginError ", "Login Fail");
                ViewBag.Email = email;
                return(View());
            }

            /// //TODO:kiểm tra tài khoản từ cơ sở dữ liệu
            /// if (email == "*****@*****.**" && password == "12345")
            /// {
            ///    // ghi nhân phiên đăng nhập của tài khoản
            //    System.Web.Security.FormsAuthentication.SetAuthCookie(email, false);
            //     // chuyển trang darhboard
            //      return RedirectToAction("Index", "Dashboard");
            // }
            //  else
            //  {
            //      ModelState.AddModelError("LoginError", "Login fail");
            //       ViewBag.Email = email;
            //       return View();
            //  }
        }