public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer          = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType  = "text/plain";

            string strUserName = StringClass.EncodeString(context.Request.Form["txtUserName"].Trim());
            string strOldPwd   = StringClass.EncodeString(context.Request.Form["txtUserPwd"]);
            string strUserPwd  = StringClass.EncryptPassword(context.Request.Form["txtUserPwd"], StringClass.PasswordFormat.MD5_32);
            bool   IsRemember  = context.Request.Form["remember"] != null ? true : false;

            if (String.IsNullOrEmpty(strUserName))
            {
                context.Response.Write("Please enter your email as user name!");
                return;
            }
            else
            {
                strUserName = StringClass.RemoveSQL(strUserName.ToLower());
            }
            if (String.IsNullOrEmpty(strOldPwd))
            {
                context.Response.Write("Please enter your password!");
                return;
            }
            else
            {
                strUserPwd = StringClass.EncryptPassword(strOldPwd, StringClass.PasswordFormat.MD5_32).ToLower();
            }
            if (context.Session["ValidateCode"] != null)
            {
                if (context.Request.Form["txtUserVal"].Trim() != context.Session["ValidateCode"].ToString())
                {
                    context.Response.Write("Validation Code is not correct!");
                    return;
                }
            }

            string error = "";

            Model.t_log_login loginLog = new Model.t_log_login();
            loginLog.ID         = Guid.NewGuid().ToString().ToLower();
            loginLog.LoginDate  = DateTime.Now;
            loginLog.IPAddress  = context.Request.ServerVariables["REMOTE_ADDR"] != null ? context.Request.ServerVariables["REMOTE_ADDR"].Trim() : "";
            loginLog.ClientInfo = context.Request.ServerVariables["Http_User_Agent"];
            Model.t_rol_user user = (new BLL.t_rol_user()).Login(strUserName, strUserPwd, loginLog);
            if (user != null && user.Password.ToLower() == strUserPwd.ToLower())
            {
                if (user.IsValid > 0)
                {
                    try
                    {
                        HttpCookie Cookie = new HttpCookie("UserCookie");
                        if (IsRemember)
                        {
                            Cookie.Expires = DateTime.Now.AddDays(7);
                        }
                        else
                        {
                            Cookie.Expires = DateTime.Now.AddDays(-1);
                        }
                        Random ra          = new Random();
                        string cookieValue = FileDecrypt.Encrypt(user.ID + "&" + user.Username, "", ra);
                        Cookie.Values.Add("cookieValue", cookieValue);

                        context.Response.Cookies.Add(Cookie);
                    }
                    catch { }
                }
                else
                {
                    error = "This user has been disabled!";
                    context.Response.Write(error);
                    return;
                }
                context.Session["User"] = user;
            }
            else
            {
                error = "Your username or passowrd is incorrect!";
                context.Response.Write(error);
                return;
            }

            string roleName = "";

            BLL.t_rol_role roleBll    = new BLL.t_rol_role();
            DataSet        roleNameDS = roleBll.GetRoleNameByRoleID(user.RoleID);

            if (roleNameDS.Tables[0].Rows.Count != 0)
            {
                roleName = roleNameDS.Tables[0].Rows[0]["RoleName"].ToString();
            }
            else
            {
                context.Response.Write("Failed to get the role.");
            }
            if (roleName == "System Administrator")
            {
                context.Response.Write("<script language='javascript'>window.location.href='/../Views/Admin/index.aspx';</script>");
            }
            if (roleName == "User")
            {
                user     = null;
                loginLog = null;
                context.Response.Write("<script language='javascript'>window.location.href='/../Views/index.aspx';</script>");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer          = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType  = "text/plain";

            StringBuilder error     = new StringBuilder();
            string        userName  = StringClass.EncodeString(context.Request.Form["txtEmail"].Trim());
            string        userPwd   = context.Request.Form["txtPwd"];
            string        userCPwd  = context.Request.Form["txtCPwd"];
            string        checkCode = context.Request.Form["txtUserVal"];

            if (!CheckInput.CheckEmail(userName))
            {
                error.Append("The email format is incorrect, Please check!<br>");
            }
            if (userPwd.Length < 6)
            {
                error.Append("The password should not be less than 6 digits.!<br>");
            }
            else
            {
                if (userPwd != userCPwd)
                {
                    error.Append("Repeated password is different from the previous!<br>");
                }
            }
            if (checkCode != context.Session["ValidateCode"].ToString())
            {
                error.Append("Wrong Validation Code!");
            }
            string userID = Guid.NewGuid().ToString().ToLower();

            if (error.ToString() == "")
            {
                Model.t_rol_user model = new Model.t_rol_user();
                model.ID          = userID;
                model.Username    = userName;
                model.Password    = StringClass.EncryptPassword(userPwd, StringClass.PasswordFormat.MD5_32);
                model.IsValid     = 1;
                model.CreatedDate = DateTime.Now;

                // Get the RoleID by RoleName. For normal User
                DataSet Ds = roleBll.GetRoleIDByRoleName("User");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    WindowClass.WindowBack("Failed to get User's Role ID!");
                }
                else
                {
                    model.RoleID = Ds.Tables[0].Rows[0]["ID"].ToString();
                }

                error.Append((new BLL.t_rol_user()).RegisterUser(model));
            }

            if (error.ToString() != "")
            {
                context.Response.Write(error.ToString());
                return;
            }
            else
            {
                Model.t_rol_user model = new Model.t_rol_user();
                model = userBll.GetModel(userID);
                if (model != null)
                {
                    context.Session["User"] = model;
                    model = null;
                    context.Response.Write("<script language='javascript'>window.location.href='/../Views/index.aspx';</script>");
                }
                else
                {
                    WindowClass.WindowBack("Failed to get User model!");
                    context.Response.Write("<script language='javascript'>window.location.href='/../Views/User/Login.aspx';</script>");
                }
            }
        }