Ejemplo n.º 1
0
        protected void OnSaveAddEditUrl(Object Sender, EventArgs args)
        {
            //try {

            RedirectController rc = new RedirectController();
            int roleId = Convert.ToInt32(ddRoles.SelectedValue);
            bool bAllUsers = false;
            bool bUnregisteredUsers = false;

            if (roleId == 0) {
                bUnregisteredUsers = true;
            } else if (roleId == -1) {
                bAllUsers = true;
            }

            rc.UpdateRedirect(roleId, bAllUsers, bUnregisteredUsers, cbKeepOnPageRef.Checked ? null : txtUrl.Text.Trim(), cbByRoleLogout.Checked, ModuleId);
            BindData();

            //} catch (Exception) {
            //    lblMsg.Visible = true;
            //    lblMsg.InnerHtml = "Error saving redirect!";
            //    lblMsg.Style["background-color"] = "#FF9999";
            //    Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
            //}
        }
Ejemplo n.º 2
0
        public bool Save()
        {
            RedirectController redirCtrl = new RedirectController();

            redirCtrl.UpdateRedirectParam(ModuleId, Param, ParamType, Operation, Value, RedirectUrl, RedirectPriority, LogoutUser);
            return(true);
        }
Ejemplo n.º 3
0
        protected void OnSaveAddEditUrl(Object Sender, EventArgs args)
        {
            //try {

            RedirectController rc   = new RedirectController();
            int  roleId             = Convert.ToInt32(ddRoles.SelectedValue);
            bool bAllUsers          = false;
            bool bUnregisteredUsers = false;

            if (roleId == 0)
            {
                bUnregisteredUsers = true;
            }
            else if (roleId == -1)
            {
                bAllUsers = true;
            }

            rc.UpdateRedirect(roleId, bAllUsers, bUnregisteredUsers, cbKeepOnPageRef.Checked ? null : txtUrl.Text.Trim(), cbByRoleLogout.Checked, ModuleId);
            BindData();

            //} catch (Exception) {
            //    lblMsg.Visible = true;
            //    lblMsg.InnerHtml = "Error saving redirect!";
            //    lblMsg.Style["background-color"] = "#FF9999";
            //    Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
            //}
        }
Ejemplo n.º 4
0
        protected void OnRowCmdParams(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();

            switch (args.CommandName)
            {
            case "del":
                redirCtrl.RemoveRedirectParam(Convert.ToInt32(args.CommandArgument));
                break;

            case "priority_up":
                RedirectInfoParam rinc = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
                rinc.RedirectPriority++;
                rinc.Save();
                break;

            case "priority_down":
                RedirectInfoParam rdec = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
                rdec.RedirectPriority--;
                rdec.Save();
                break;
            }

            BindData();
        }
Ejemplo n.º 5
0
        protected void OnRowCmdRef(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();
            switch (args.CommandName) {
                case "del":
                    redirCtrl.RemoveRedirectRef(Convert.ToInt32(args.CommandArgument));
                    break;
            }

            BindData();
        }
Ejemplo n.º 6
0
        protected void OnRowCmdRef(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();

            switch (args.CommandName)
            {
            case "del":
                redirCtrl.RemoveRedirectRef(Convert.ToInt32(args.CommandArgument));
                break;
            }

            BindData();
        }
Ejemplo n.º 7
0
        protected void OnSaveRefAddEditUrl(Object Sender, EventArgs args)
        {
            //try {

            RedirectController rc = new RedirectController();

            rc.UpdateRedirectRef(tbReferrer.Text.Trim(), cbKeepOnPageRef.Checked ? null : txtUrlRef.Text.Trim(), cbUrlRefMathDomain.Checked, ModuleId);
            BindData();

            //} catch (Exception) {
            //    lblMsg.Visible = true;
            //    lblMsg.InnerHtml = "Error saving redirect!";
            //    lblMsg.Style["background-color"] = "#FF9999";
            //    Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
            //}
        }
Ejemplo n.º 8
0
        protected void OnRowCmd(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();
            switch (args.CommandName) {
                case "del":
                    redirCtrl.RemoveRedirect(Convert.ToInt32(args.CommandArgument));
                    break;
                case "priority_up":
                    redirCtrl.IncreasePriority(Convert.ToInt32(args.CommandArgument));
                    break;
                case "priority_down":
                    redirCtrl.DecreasePriority(Convert.ToInt32(args.CommandArgument));
                    break;
            }

            BindData();
        }
Ejemplo n.º 9
0
        protected void OnRowCmdParams(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();
            switch (args.CommandName) {
                case "del":
                    redirCtrl.RemoveRedirectParam(Convert.ToInt32(args.CommandArgument));
                    break;
                case "priority_up":
                    RedirectInfoParam rinc = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
                    rinc.RedirectPriority++;
                    rinc.Save();
                    break;
                case "priority_down":
                    RedirectInfoParam rdec = redirCtrl.GetRedirectParamById(Convert.ToInt32(args.CommandArgument));
                    rdec.RedirectPriority--;
                    rdec.Save();
                    break;
            }

            BindData();
        }
Ejemplo n.º 10
0
        protected void OnRowCmd(Object Sender, GridViewCommandEventArgs args)
        {
            RedirectController redirCtrl = new RedirectController();

            switch (args.CommandName)
            {
            case "del":
                redirCtrl.RemoveRedirect(Convert.ToInt32(args.CommandArgument));
                break;

            case "priority_up":
                redirCtrl.IncreasePriority(Convert.ToInt32(args.CommandArgument));
                break;

            case "priority_down":
                redirCtrl.DecreasePriority(Convert.ToInt32(args.CommandArgument));
                break;
            }

            BindData();
        }
Ejemplo n.º 11
0
        protected void Redirect()
        {
            RedirectController       redirCtrl      = new RedirectController();
            ArrayList                redirectsRef   = redirCtrl.GetRedirectsRef(ModuleId);
            ArrayList                redirects      = redirCtrl.GetRedirects(PortalId, ModuleId);
            List <RedirectInfoParam> redirectsParam = redirCtrl.GetRedirectsParam(ModuleId);

            ModuleController modCtrl = new ModuleController();
            //Hashtable modSettings = modCtrl.GetModuleSettings(ModuleId);
            var module      = modCtrl.GetModule(ModuleId);
            var modSettings = module.ModuleSettings;

            string redirUrl = null;

            bool bLogout;

            try {
                bLogout = Convert.ToBoolean(modSettings["LogoutUser"].ToString());
            } catch { bLogout = false; }

            // check parameters
            foreach (RedirectInfoParam redInfo in redirectsParam)
            {
                NameValueCollection collection = null;
                switch (redInfo.ParamType)
                {
                case RedirectInfoParam.eParamType.GET:
                    collection = Request.QueryString;
                    break;

                case RedirectInfoParam.eParamType.POST:
                    collection = Request.Form;
                    break;

                case RedirectInfoParam.eParamType.GET_POST:
                    collection = Request.Params;
                    break;
                }

                if (collection == null)
                {
                    continue;
                }

                // check if matches

                bool   bMatch     = false;
                string paramName  = Tokenize(redInfo.Param);
                string paramValue = Tokenize(redInfo.Value);

                if (collection[paramName] == null)
                {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.NotExists)
                    {
                        bMatch = true;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.Exists)
                    {
                        bMatch = true;
                    }
                }

                if (bMatch == false)
                {
                    switch (redInfo.Operation)
                    {
                    case RedirectInfoParam.eOperation.Equals:
                        if (paramValue == collection[paramName])
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.NotEquals:
                        if (paramValue != collection[paramName])
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.Contains:
                        if (collection[paramName].Contains(paramValue))
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.NotContains:
                        if (!collection[paramName].Contains(paramValue))
                        {
                            bMatch = true;
                        }
                        break;
                    }
                }

                if (bMatch)
                {
                    redirUrl = redInfo.RedirectUrl;
                    bLogout  = redInfo.LogoutUser;
                    if (string.IsNullOrEmpty(redirUrl))
                    {
                        CheckLogout(bLogout);
                        return; // keep on page
                    }
                    break;
                }
            }

            // check referrers first
            if (redirUrl == null)
            {
                string urlReferrer = "";
                if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
                {
                    urlReferrer = Request.UrlReferrer.ToString();
                }

                foreach (RedirectRefInfo redInfo in redirectsRef)
                {
                    string checkRef = Tokenize(redInfo.Referrer);

                    if (redInfo.MatchDomainOnly)
                    {
                        if (urlReferrer.IndexOf(checkRef) == 0)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (checkRef == urlReferrer)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // check which one matches
            if (redirUrl == null)
            {
                foreach (RedirectInfo redInfo in redirects)
                {
                    if (redInfo.RoleId > 0)
                    {
                        if (UserInfo.IsInRole(redInfo.RoleName))
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (redInfo.RoleUnregisteredUsers && UserInfo.UserID <= 0)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                        else if (redInfo.RoleAllUsers)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // see if we have get param
            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("GetParam") && modSettings["GetParam"].ToString().Length > 0)
                {
                    if (!String.IsNullOrEmpty(Request.QueryString[modSettings["GetParam"].ToString()]))
                    {
                        redirUrl = Request.QueryString[modSettings["GetParam"].ToString()];
                    }
                }
            }

            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("GetParamRef") && modSettings["GetParamRef"].ToString().Length > 0)
                {
                    try {
                        Match m = Regex.Match(Request.UrlReferrer.ToString(), modSettings["GetParamRef"].ToString() + "=([^&]+)");
                        if (!String.IsNullOrEmpty(m.Groups[1].Captures[0].Value))
                        {
                            redirUrl = m.Groups[1].Captures[0].Value;
                        }
                    } catch {
                    }
                }
            }

            // we're up to default url
            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("DefaultUrl") && modSettings["DefaultUrl"].ToString().Length > 0)
                {
                    redirUrl = modSettings["DefaultUrl"].ToString();
                }
            }

            if (redirUrl == null)
            {
                // redirect failed
                //pnlRedirectUser.Visible = true;
                //pnlRedirectUser.InnerHtml = "<b>Redirect Failed!<b/><br/><br/>There is no redirect defined for current role.";
                CheckLogout(bLogout);
                return;
            }

            redirUrl = redirUrl.Trim();

            // apply tokens
            redirUrl = Tokenize(redirUrl);


            CheckLogout(bLogout);

            Response.Redirect(redirUrl);
        }
 public bool Save()
 {
     RedirectController redirCtrl = new RedirectController();
     redirCtrl.UpdateRedirectParam(ModuleId, Param, ParamType, Operation, Value, RedirectUrl, RedirectPriority, LogoutUser);
     return true;
 }
Ejemplo n.º 13
0
        private void BindData()
        {
            if (!TokenReplacer.IsMyTokensInstalled()) {
                lblMyTokensRefUrl.InnerHtml = lblMyTokensParamVal.InnerHtml = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (get it <a href = 'http://www.avatar-soft.ro/Products/MyTokens/tabid/148/Default.aspx'>here</a>)";
            } else {
                lblMyTokensRefUrl.InnerHtml = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (installed)";
                lblMyTokensParamVal.InnerHtml = lblMyTokens.InnerHtml = "both parameter name and value can contain MyTokens (installed)";
            }

            // clear form
            txtUrl.Text = "";
            txtUrlRef.Text = "";
            cbKeepOnPage.Checked = false;
            cbKeepOnPageRef.Checked = false;
            cbByRoleLogout.Checked = false;
            reqUrl.IsValid = true;

            tbReferrer.Text = "";
            txtUrlRef.Text = "";
            reqUrlRef.IsValid = true;
            cbUrlRefMathDomain.Checked = false;
            cbKeepOnPageRef.Checked = false;

            cbParamRed_Logout.Checked = false;
            cbParamRed_KeepOnPage.Checked = false;
            tbParamRed_Url.Text = "";
            tbParamRed_Name.Text = "";
            tbParamRed_Value.Text = "";
            reqUrlParam.IsValid = true;
            ddParamOp.ClearSelection();
            ddParamOp.SelectedIndex = 0;
            ddParamType.ClearSelection();
            ddParamType.SelectedIndex = 0;

            // bind settings
            ModuleController modCtrl = new ModuleController();
            try {
                txtGetParam.Text = modCtrl.GetModuleSettings(ModuleId)["GetParam"].ToString();
            } catch {
                txtGetParam.Text = "";
            }
            try {
                txtGetParamRefferer.Text = modCtrl.GetModuleSettings(ModuleId)["GetParamRef"].ToString();
            } catch {
                txtGetParamRefferer.Text = "";
            }
            try {
                txtDefaultUrl.Text = modCtrl.GetModuleSettings(ModuleId)["DefaultUrl"].ToString();
            } catch {
                txtDefaultUrl.Text = "";
            }
            try {
                cbLogout.Checked = Convert.ToBoolean(modCtrl.GetModuleSettings(ModuleId)["LogoutUser"].ToString());
            } catch {
                cbLogout.Checked = false;
            }

            // bind roles DD
            ddRoles.ClearSelection();
            ddRoles.Items.Clear();

            RoleController roleCtrl = new RoleController();
            ArrayList roles = roleCtrl.GetPortalRoles(PortalId);

            // remove admin role
            foreach (RoleInfo rInfo in roles) {
                if (rInfo.RoleID == PortalSettings.AdministratorRoleId) {
                    roles.Remove(rInfo);
                    break;
                }
            }

            // now, add All Users and Unregistered Users
            roles.Insert(0, new RoleInfo() { RoleID = 0, RoleName = "Unregistered Users" });
            roles.Insert(0, new RoleInfo() { RoleID = -1, RoleName = "All Users" });

            ddRoles.DataTextField = "RoleName";
            ddRoles.DataValueField = "RoleID";
            ddRoles.DataSource = roles;
            ddRoles.DataBind();

            // bind redirects table
            GetDbConfig();
            sqlDataSource.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirects";
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add(new Parameter() { Name = "portalId", DefaultValue = PortalId.ToString() });
            sqlDataSource.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
            sqlDataSource.DataBind();
            vwRedirects.DataBind();

            // bind redirects ref table
            sqlDataSourceRef.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsRef";
            sqlDataSourceRef.SelectParameters.Clear();
            sqlDataSourceRef.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
            sqlDataSourceRef.DataBind();
            vwRedirectsRef.DataBind();

            // bind redirects param table
            sqlDataSourceParam.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsParam";
            sqlDataSourceParam.SelectParameters.Clear();
            sqlDataSourceParam.SelectParameters.Add(new Parameter() { Name = "moduleId", DefaultValue = ModuleId.ToString() });
            sqlDataSourceParam.DataBind();
            vwRedirectsParam.DataBind();

            RedirectController redirCtrl = new RedirectController();

            cbKeepOnPage.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrl.ClientID + "'), !this.checked);";
            cbKeepOnPageRef.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrlRef.ClientID + "'), !this.checked);";
            cbParamRed_KeepOnPage.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrlParam.ClientID + "'), !this.checked);";
            if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
                cReferrer.InnerHtml = "Current Referrer: " + Request.UrlReferrer.ToString();
            else
                cReferrer.InnerHtml = "Current Referrer: <i>none</i>";

            // set validation groups
            txtGetParam.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
            txtGetParamRefferer.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
            txtDefaultUrl.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
            cbLogout.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
            cmdSaveSettings.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";

            tbParamRed_Url.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
            cbParamRed_Logout.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
            cmdSaveParamAddEditUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
            reqUrlParam.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";

            txtUrlRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
            cmdUpdateRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
            reqUrlRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";

            txtUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
            cbByRoleLogout.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
            cmdUpdate.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
            reqUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
        }
Ejemplo n.º 14
0
        protected void OnSaveRefAddEditUrl(Object Sender, EventArgs args)
        {
            //try {

            RedirectController rc = new RedirectController();
            rc.UpdateRedirectRef(tbReferrer.Text.Trim(), cbKeepOnPageRef.Checked ? null : txtUrlRef.Text.Trim(), cbUrlRefMathDomain.Checked, ModuleId);
            BindData();

            //} catch (Exception) {
            //    lblMsg.Visible = true;
            //    lblMsg.InnerHtml = "Error saving redirect!";
            //    lblMsg.Style["background-color"] = "#FF9999";
            //    Page.ClientScript.RegisterStartupScript(GetType(), "timeoutSuccessMsg", "<script type='text/javascript'>setTimeout(function() { document.getElementById('" + lblMsg.ClientID + "').style.display = 'none'; }, 6000);</script>");
            //}
        }
Ejemplo n.º 15
0
        protected void Redirect()
        {
            RedirectController redirCtrl = new RedirectController();
            ArrayList redirectsRef = redirCtrl.GetRedirectsRef(ModuleId);
            ArrayList redirects = redirCtrl.GetRedirects(PortalId, ModuleId);
            List<RedirectInfoParam> redirectsParam = redirCtrl.GetRedirectsParam(ModuleId);

            ModuleController modCtrl = new ModuleController();
            Hashtable modSettings = modCtrl.GetModuleSettings(ModuleId);

            string redirUrl = null;

            bool bLogout;
            try {
                bLogout = Convert.ToBoolean(modCtrl.GetModuleSettings(ModuleId)["LogoutUser"].ToString());
            } catch { bLogout = false; }

            // check parameters
            foreach (RedirectInfoParam redInfo in redirectsParam) {

                NameValueCollection collection = null;
                switch (redInfo.ParamType) {
                    case RedirectInfoParam.eParamType.GET:
                        collection = Request.QueryString;
                        break;
                    case RedirectInfoParam.eParamType.POST:
                        collection = Request.Form;
                        break;
                    case RedirectInfoParam.eParamType.GET_POST:
                        collection = Request.Params;
                        break;
                }

                if (collection == null)
                    continue;

                // check if matches

                bool bMatch = false;
                string paramName = Tokenize(redInfo.Param);
                string paramValue =Tokenize(redInfo.Value);

                if (collection[paramName] == null) {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.NotExists) {
                        bMatch = true;
                    } else { continue; }
                } else {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.Exists) {
                        bMatch = true;
                    }
                }

                if (bMatch == false) {
                    switch (redInfo.Operation) {
                        case RedirectInfoParam.eOperation.Equals:
                            if (paramValue == collection[paramName])
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.NotEquals:
                            if (paramValue != collection[paramName])
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.Contains:
                            if (collection[paramName].Contains(paramValue))
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.NotContains:
                            if (!collection[paramName].Contains(paramValue))
                                bMatch = true;
                            break;
                    }
                }

                if (bMatch) {
                    redirUrl = redInfo.RedirectUrl;
                    bLogout = redInfo.LogoutUser;
                    if (string.IsNullOrEmpty(redirUrl)) {
                        CheckLogout(bLogout);
                        return; // keep on page
                    }
                    break;
                }
            }

            // check referrers first
            if (redirUrl == null) {
                string urlReferrer = "";
                if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString())) {
                    urlReferrer = Request.UrlReferrer.ToString();
                }

                foreach (RedirectRefInfo redInfo in redirectsRef) {

                    string checkRef = Tokenize(redInfo.Referrer);

                    if (redInfo.MatchDomainOnly) {
                        if (urlReferrer.IndexOf(checkRef) == 0) {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    } else {
                        if (checkRef == urlReferrer) {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // check which one matches
            if (redirUrl == null) {
                foreach (RedirectInfo redInfo in redirects) {
                    if (redInfo.RoleId > 0) {
                        if (UserInfo.IsInRole(redInfo.RoleName)) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    } else {
                        if (redInfo.RoleUnregisteredUsers && UserInfo.UserID <= 0) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        } else if (redInfo.RoleAllUsers) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // see if we have get param
            if (redirUrl == null) {
                if (modSettings.ContainsKey("GetParam") && modSettings["GetParam"].ToString().Length > 0) {
                    if (!String.IsNullOrEmpty(Request.QueryString[modSettings["GetParam"].ToString()])) {
                        redirUrl = Request.QueryString[modSettings["GetParam"].ToString()];
                    }
                }
            }

            if (redirUrl == null) {
                if (modSettings.ContainsKey("GetParamRef") && modSettings["GetParamRef"].ToString().Length > 0) {
                    try {
                        Match m = Regex.Match(Request.UrlReferrer.ToString(), modSettings["GetParamRef"].ToString() + "=([^&]+)");
                        if (!String.IsNullOrEmpty(m.Groups[1].Captures[0].Value)) {
                            redirUrl = m.Groups[1].Captures[0].Value;
                        }
                    } catch {
                    }
                }
            }

            // we're up to default url
            if (redirUrl == null) {
                if (modSettings.ContainsKey("DefaultUrl") && modSettings["DefaultUrl"].ToString().Length > 0) {
                    redirUrl = modSettings["DefaultUrl"].ToString();
                }
            }

            if (redirUrl == null) {
                // redirect failed
                //pnlRedirectUser.Visible = true;
                //pnlRedirectUser.InnerHtml = "<b>Redirect Failed!<b/><br/><br/>There is no redirect defined for current role.";
                CheckLogout(bLogout);
                return;
            }

            redirUrl = redirUrl.Trim();

            // apply tokens
            redirUrl = Tokenize(redirUrl);

            CheckLogout(bLogout);

            Response.Redirect(redirUrl);
        }
Ejemplo n.º 16
0
        private void BindData()
        {
            if (!TokenReplacer.IsMyTokensInstalled())
            {
                lblMyTokensRefUrl.InnerHtml = lblMyTokensParamVal.InnerHtml = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (get it <a href = 'http://www.avatar-soft.ro/Products/MyTokens/tabid/148/Default.aspx'>here</a>)";
            }
            else
            {
                lblMyTokensRefUrl.InnerHtml   = lblMyTokensParam.InnerHtml = lblMyTokensRef.InnerHtml = lblMyTokens.InnerHtml = "can contain MyTokens (installed)";
                lblMyTokensParamVal.InnerHtml = lblMyTokens.InnerHtml = "both parameter name and value can contain MyTokens (installed)";
            }

            // clear form
            txtUrl.Text             = "";
            txtUrlRef.Text          = "";
            cbKeepOnPage.Checked    = false;
            cbKeepOnPageRef.Checked = false;
            cbByRoleLogout.Checked  = false;
            reqUrl.IsValid          = true;

            tbReferrer.Text            = "";
            txtUrlRef.Text             = "";
            reqUrlRef.IsValid          = true;
            cbUrlRefMathDomain.Checked = false;
            cbKeepOnPageRef.Checked    = false;

            cbParamRed_Logout.Checked     = false;
            cbParamRed_KeepOnPage.Checked = false;
            tbParamRed_Url.Text           = "";
            tbParamRed_Name.Text          = "";
            tbParamRed_Value.Text         = "";
            reqUrlParam.IsValid           = true;
            ddParamOp.ClearSelection();
            ddParamOp.SelectedIndex = 0;
            ddParamType.ClearSelection();
            ddParamType.SelectedIndex = 0;

            // bind settings
            ModuleController modCtrl = new ModuleController();

            try {
                txtGetParam.Text = modCtrl.GetModuleSettings(ModuleId)["GetParam"].ToString();
            } catch {
                txtGetParam.Text = "";
            }
            try {
                txtGetParamRefferer.Text = modCtrl.GetModuleSettings(ModuleId)["GetParamRef"].ToString();
            } catch {
                txtGetParamRefferer.Text = "";
            }
            try {
                txtDefaultUrl.Text = modCtrl.GetModuleSettings(ModuleId)["DefaultUrl"].ToString();
            } catch {
                txtDefaultUrl.Text = "";
            }
            try {
                cbLogout.Checked = Convert.ToBoolean(modCtrl.GetModuleSettings(ModuleId)["LogoutUser"].ToString());
            } catch {
                cbLogout.Checked = false;
            }


            // bind roles DD
            ddRoles.ClearSelection();
            ddRoles.Items.Clear();

            RoleController roleCtrl = new RoleController();
            ArrayList      roles    = roleCtrl.GetPortalRoles(PortalId);

            // remove admin role
            foreach (RoleInfo rInfo in roles)
            {
                if (rInfo.RoleID == PortalSettings.AdministratorRoleId)
                {
                    roles.Remove(rInfo);
                    break;
                }
            }

            // now, add All Users and Unregistered Users
            roles.Insert(0, new RoleInfo()
            {
                RoleID = 0, RoleName = "Unregistered Users"
            });
            roles.Insert(0, new RoleInfo()
            {
                RoleID = -1, RoleName = "All Users"
            });

            ddRoles.DataTextField  = "RoleName";
            ddRoles.DataValueField = "RoleID";
            ddRoles.DataSource     = roles;
            ddRoles.DataBind();

            // bind redirects table
            GetDbConfig();
            sqlDataSource.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirects";
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add(new Parameter()
            {
                Name = "portalId", DefaultValue = PortalId.ToString()
            });
            sqlDataSource.SelectParameters.Add(new Parameter()
            {
                Name = "moduleId", DefaultValue = ModuleId.ToString()
            });
            sqlDataSource.DataBind();
            vwRedirects.DataBind();

            // bind redirects ref table
            sqlDataSourceRef.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsRef";
            sqlDataSourceRef.SelectParameters.Clear();
            sqlDataSourceRef.SelectParameters.Add(new Parameter()
            {
                Name = "moduleId", DefaultValue = ModuleId.ToString()
            });
            sqlDataSourceRef.DataBind();
            vwRedirectsRef.DataBind();

            // bind redirects param table
            sqlDataSourceParam.SelectCommand = _databaseOwner + _objectQualifier + "avtRedirect_GetRedirectsParam";
            sqlDataSourceParam.SelectParameters.Clear();
            sqlDataSourceParam.SelectParameters.Add(new Parameter()
            {
                Name = "moduleId", DefaultValue = ModuleId.ToString()
            });
            sqlDataSourceParam.DataBind();
            vwRedirectsParam.DataBind();


            RedirectController redirCtrl = new RedirectController();

            cbKeepOnPage.Attributes["onclick"]          = "ValidatorEnable(document.getElementById('" + reqUrl.ClientID + "'), !this.checked);";
            cbKeepOnPageRef.Attributes["onclick"]       = "ValidatorEnable(document.getElementById('" + reqUrlRef.ClientID + "'), !this.checked);";
            cbParamRed_KeepOnPage.Attributes["onclick"] = "ValidatorEnable(document.getElementById('" + reqUrlParam.ClientID + "'), !this.checked);";
            if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
            {
                cReferrer.InnerHtml = "Current Referrer: " + Request.UrlReferrer.ToString();
            }
            else
            {
                cReferrer.InnerHtml = "Current Referrer: <i>none</i>";
            }


            // set validation groups
            txtGetParam.ValidationGroup         = ModuleId.ToString() + "_avtValidRedirectSettings";
            txtGetParamRefferer.ValidationGroup = ModuleId.ToString() + "_avtValidRedirectSettings";
            txtDefaultUrl.ValidationGroup       = ModuleId.ToString() + "_avtValidRedirectSettings";
            cbLogout.ValidationGroup            = ModuleId.ToString() + "_avtValidRedirectSettings";
            cmdSaveSettings.ValidationGroup     = ModuleId.ToString() + "_avtValidRedirectSettings";

            tbParamRed_Url.ValidationGroup         = ModuleId.ToString() + "avtValidRedirectParam";
            cbParamRed_Logout.ValidationGroup      = ModuleId.ToString() + "avtValidRedirectParam";
            cmdSaveParamAddEditUrl.ValidationGroup = ModuleId.ToString() + "avtValidRedirectParam";
            reqUrlParam.ValidationGroup            = ModuleId.ToString() + "avtValidRedirectParam";

            txtUrlRef.ValidationGroup    = ModuleId.ToString() + "avtValidRedirectRef";
            cmdUpdateRef.ValidationGroup = ModuleId.ToString() + "avtValidRedirectRef";
            reqUrlRef.ValidationGroup    = ModuleId.ToString() + "avtValidRedirectRef";

            txtUrl.ValidationGroup         = ModuleId.ToString() + "avtValidRedirect";
            cbByRoleLogout.ValidationGroup = ModuleId.ToString() + "avtValidRedirect";
            cmdUpdate.ValidationGroup      = ModuleId.ToString() + "avtValidRedirect";
            reqUrl.ValidationGroup         = ModuleId.ToString() + "avtValidRedirect";
        }