Example #1
0
        protected void btLogon_Click(object sender, EventArgs e)
        {
            if (_userDAL.Login(txtUsername.Text, txtPassword.Text))
            {
                if (Convert.ToInt32(Session["capchaimgvna"]) >= 3)
                {
                    if (Session["captcha"] != null)
                    {
                        if (Session["captcha"].ToString() != txtCaptcha.Text)
                        {
                            FuncAlert.AlertJS(this, "Mã bảo mật không đúng!");
                            return;
                        }
                    }
                }
                if (this.txtUsername.Text.Length > 0 && this.txtPassword.Text.Length > 0)
                {
                    user = _userDAL.GetUserByUserPass(txtUsername.Text, txtPassword.Text);
                }
                if (user.UserActive)
                {
                    FormsAuthentication.SetAuthCookie(user.UserName, false);
                    HttpCookie cookie = new HttpCookie("hpcinfomation");
                    cookie.Values.Add("hpcUserNames", txtUsername.Text.Trim());
                    cookie.Values.Add("hpcPassword", txtPassword.Text.Trim());
                    cookie.Expires = DateTime.Now.AddMinutes(60);
                    Response.Cookies.Add(cookie);
                    //Phan message
                    _userLog = SetItem(user);
                    _dalchat.InsertT_UserLogin(_userLog);
                    //end
                    UltilFunc.Log_Action(user.UserID, user.UserFullName, DateTime.Now, 0, "Đăng nhập hệ thống thành công");

                    Response.Redirect(Global.ApplicationPath + "/Dungchung/Commons.aspx");
                }
                else
                {
                    if (Session["capchaimgvna"] == null)
                    {
                        Session["capchaimgvna"] = "1";
                    }
                    else
                    {
                        Session["capchaimgvna"] = Convert.ToInt32(Session["capchaimgvna"]) + 1;
                        if (Convert.ToInt32(Session["capchaimgvna"]) >= 3)
                        {
                            pnlcapcha.Visible = true;
                        }
                    }
                    FuncAlert.AlertJS(this, "Tài khoản của bạn đang bị khóa. Liên hệ quản trị!");
                    FillCapctha();
                }
            }
            else
            {
                if (Session["capchaimgvna"] == null)
                {
                    Session["capchaimgvna"] = "1";
                }
                else
                {
                    Session["capchaimgvna"] = Convert.ToInt32(Session["capchaimgvna"]) + 1;
                    if (Convert.ToInt32(Session["capchaimgvna"]) >= 3)
                    {
                        this.pnlcapcha.Visible = true;
                    }
                }
                FuncAlert.AlertJS(this, "Đăng nhập không thành công");
                FillCapctha();
            }
        }