Ejemplo n.º 1
0
        public ActionResult Login(string username, string password, string url, string remember)
        {
            ViewBag.url = url;

            if (Session[AppSessionKeys.USER_INFO] == null)
            {
                if (string.IsNullOrEmpty(username))
                {
                    ViewBag.error = "Chưa nhập Tên đăng nhập";
                    return(View());
                }
                if (string.IsNullOrEmpty(password))
                {
                    ViewBag.error = "Chưa nhập Mật khẩu";
                    return(View());
                }
                string newPass = GetMD5Hash(password); // pass MD5

                VIEW_INFO_USER_LOGIN user = Users_Service.CheckLogin(username, password);
                if (user == null)
                {
                    ViewBag.error = "Đăng nhập sai hoặc bạn không có quyền vào";
                    return(View());
                }
                else
                {
                    Session[AppSessionKeys.USER_INFO] = user;
                    if (remember == "on")
                    {
                        AppCookieInfo.UserID         = username;
                        AppCookieInfo.HashedPassword = password;
                    }
                    else
                    {
                        AppCookieInfo.RemoveAllCookies();
                    }
                    //OK
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectPermanent(url));
            }
        }
Ejemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         AppCookieInfo.RemoveAllCookies();
         AppSessionInfo.CurrentUser = null;
         Session.Clear();
         CookieHelper.RemoveCookie(AppCookieKeys.USERID);
     }
     catch (Exception)
     {
         Response.Redirect(AppUrls.LOGIN);
         throw;
     }
 }