Esempio n. 1
0
        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            UsersDH ctlUser = new UsersDH();
            User    objUser = ctlUser.validateLogin(txtUser.Text, Utils.Encrypt(txtPassword.Text));

            if (objUser == null)
            {
                Utils.notifierPage(Page, this.GetType(), Constant.NOTIFY_FAILURE, "Tên đăng nhập hoặc mật khẩu không chính xác.", Constant.TIME_ERROR);
                return;
            }
            List <MenuItemFunction> lstMenuItem = ctlUser.getMenuItem(objUser);

            if (objUser != null)
            {
                if (objUser.LockoutEnabled)
                {
                    Utils.notifierPage(Page, this.GetType(), Constant.NOTIFY_FAILURE, "Tài khoản của bạn đã bị khóa.", Constant.TIME_ERROR);
                    return;
                }
                HttpCookie cookie = Request.Cookies[Constant.USER_COOKIE];
                if (cookie == null)
                {
                    cookie = new HttpCookie(Constant.USER_COOKIE);
                }
                StringBuilder lst = new StringBuilder();
                foreach (MenuItemFunction item in lstMenuItem)
                {
                    lst.Append("," + item.Path);
                }
                if (lstMenuItem.Count == 0)
                {
                    cookie[Constant.FUNCTION_COOKIE] = Utils.Encrypt("<>");
                }
                else
                {
                    cookie[Constant.FUNCTION_COOKIE] = Utils.Encrypt(lst.ToString().Substring(1));
                }
                cookie[Constant.NAME_COOKIE] = Utils.Encrypt(objUser.Id_Login);

                if (chkGiuDN.Checked)
                {
                    cookie.Expires = DateTime.Now.AddDays(30);
                }
                else
                {
                    cookie.Expires = DateTime.Now.AddMinutes(50);
                }


                Response.Cookies.Add(cookie);
                Response.Redirect("~/DashBoard.aspx");
            }
        }
Esempio n. 2
0
 protected void PopupDoiMatKhau_WindowCallback(object source, DevExpress.Web.PopupWindowCallbackArgs e)
 {
     try
     {
         //Xu ly callback popup doi mat khau
         String strerror = "";
         String result   = CustomValidate.checkControlEmpty(pnPopupChangePassword, new String[] { "txtMatKhauCu", "txtMatKhauMoi", "txtXacNhanMatKhauMoi" });
         if (result != null)
         {
             PopupDoiMatKhau.JSProperties["cpUpdateStatus"] = Constant.NOTIFY_FAILURE;
             PopupDoiMatKhau.JSProperties["cpMess"]         = result;
             return;
         }
         HttpCookie cookie = Request.Cookies[Constant.USER_COOKIE];
         if (cookie == null)
         {
             Response.Redirect("~/Login/Login.aspx");
         }
         UsersDH ctlUser = new UsersDH();
         String  UserLog = Utils.Decrypt(cookie[Constant.NAME_COOKIE]);
         User    objUser = ctlUser.validateLogin(UserLog, Utils.Encrypt(txtMatKhauCu.Text));
         if (objUser == null)
         {
             PopupDoiMatKhau.JSProperties["cpUpdateStatus"] = Constant.NOTIFY_FAILURE;
             PopupDoiMatKhau.JSProperties["cpMess"]         = "Mật khẩu cũ bạn nhập không chính xác.";
             return;
         }
         if (!txtMatKhauMoi.Text.Equals(txtXacNhanMatKhauMoi.Text))
         {
             PopupDoiMatKhau.JSProperties["cpUpdateStatus"] = Constant.NOTIFY_FAILURE;
             PopupDoiMatKhau.JSProperties["cpMess"]         = "Xác nhận mật khẩu không chính xác.";
             return;
         }
         ctlUser.updateUserPassword(UserLog, Utils.Encrypt(txtMatKhauMoi.Text));
         PopupDoiMatKhau.JSProperties["cpUpdateStatus"] = Constant.NOTIFY_SUCCESS;
         PopupDoiMatKhau.JSProperties["cpMess"]         = String.Format("Cập nhập mật khẩu cho tài khoản [{0}] thành công.", UserLog);
         return;
     }
     catch (Exception ex)
     {
         PopupDoiMatKhau.JSProperties["cpUpdateStatus"] = Constant.NOTIFY_FAILURE;
         PopupDoiMatKhau.JSProperties["cpMess"]         = ex.Message + " " + ex.StackTrace;
     }
 }