protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack && Convert.ToInt32(Session["retryAuth"]) != Convert.ToInt32(ConfigurationManager.AppSettings["PersonifyRetryCount"]))
        {
            _wsSso = new service {
                Url = _personifySsoUrl
            };

            if (Request.QueryString["action"] == "logout")
            {
                string returnUrl;

                if (Request.QueryString["returnUrl"] != null && !string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
                {
                    returnUrl = Request.QueryString["returnUrl"];
                }
                else
                {
                    returnUrl = Request.ServerVariables["PATH_INFO"];
                }

                if (_wsSso != null)
                {
                    _wsSso.Dispose();
                }


                if (returnUrl.ToLower().Trim().Contains("?logging_out") == false)
                {
                    returnUrl = returnUrl + "?logging_out=true";
                }

                Response.Redirect(returnUrl, true);
            }
            else
            {
                if (!(CMS.Membership.AuthenticationHelper.IsAuthenticated()))
                {
                    try
                    {
                        CheckSsoToken();
                    }
                    catch (Exception execp)
                    {
                        EventLogProvider.LogException(execp.Source, execp.StackTrace, execp);
                    }
                }
                else
                {
                    bool flagpersonifyMember = false;

                    if (CMS.Membership.AuthenticationHelper.IsAuthenticated())
                    {
                        UserInfo userdata =
                            CMS.Membership.UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserName);

                        DataTable dt = UserInfoProvider.GetUserRoles(userdata);

                        if (dt.Rows.Count > 0 && dt != null)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr["RoleName"].ToString().ToLower().Contains("peronifyuser"))
                                {
                                    flagpersonifyMember = true;
                                }
                            }
                        }
                    }

                    if (Session[PersonifySessionKey] == null && flagpersonifyMember)
                    {
                        objKenticoService.Logout(MembershipContext.AuthenticatedUser.UserName);
                    }
                }
            }
        }
    }
Пример #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // LoginMember("*****@*****.**", "Password1", true);
        if (!Page.IsPostBack)
        {
            _wsSso = new service {
                Url = _personifySsoUrl
            };

            if (Request.QueryString["action"] == "logout")
            {
                //  var userApi = new UserAPI();
                //  Logout(userApi, Session[PersonifySessionKey] != null ? Session[PersonifySessionKey].ToString() : null);
                //  objKenticoService.Logout("");
                string returnUrl;

                if (Request.QueryString["returnUrl"] != null && !string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
                {
                    returnUrl = Request.QueryString["returnUrl"];
                }
                else
                {
                    returnUrl = Request.ServerVariables["PATH_INFO"];
                }

                if (_wsSso != null)
                {
                    _wsSso.Dispose();
                }


                if (returnUrl.ToLower().Trim().Contains("?logging_out") == false)
                {
                    returnUrl = returnUrl + "?logging_out=true";
                }

                Response.Redirect(returnUrl, true);
            }
            else
            {
                if (!(CMS.Membership.AuthenticationHelper.IsAuthenticated()))
                {
                    CheckSsoToken();
                }
                else
                {
                    bool flagpersonifyMember = false;

                    if (CMS.Membership.AuthenticationHelper.IsAuthenticated())
                    {
                        UserInfo userdata =
                            CMS.Membership.UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserName);

                        DataTable dt = UserInfoProvider.GetUserRoles(userdata);

                        if (dt.Rows.Count > 0 && dt != null)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr["RoleName"].ToString().ToLower().Contains("peronifyuser"))
                                {
                                    flagpersonifyMember = true;
                                }
                            }
                        }
                    }

                    if (Session[PersonifySessionKey] == null && flagpersonifyMember)
                    {
                        objKenticoService.Logout(MembershipContext.AuthenticatedUser.UserName);
                    }
                }
            }
        }
    }
    private void CheckSsoToken()
    {
        bool loggedin = objKenticoService.CheckLoginUser("");

        if (!loggedin)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ct"]))
            {
                var customerToken = Request.QueryString["ct"];
                Session["cuctomerReturnToken"] = customerToken;
                var decryptedToken = DecryptCustomerToken(customerToken);
                Session["OpenLoginBox"] = true;

                var finalToken = "";
                if (decryptedToken != "")
                {
                    finalToken = ValidateCustomerToken(decryptedToken);
                }
                // in case of corrupted decrypted token, until success, retry authentication x times as specified in web config to get new customer token
                if (finalToken == null && Convert.ToInt32(Session["retryAuth"]) < Convert.ToInt32(ConfigurationManager.AppSettings["PersonifyRetryCount"]))
                {
                    EventLogProvider.LogInformation("Personify corrupt decryption string", "Personify", "customer token: " + customerToken + "decrypted token: " + decryptedToken);
                    RetryAuth();
                }
                Session.Remove("uname");
                Session.Remove("pwd");
                var    customerIdentifier = "";
                string emailaddress       = null;
                string userName           = null;

                if (finalToken != "")
                {
                    customerIdentifier          = ValidateUser(finalToken, ref emailaddress, ref userName);
                    Session["PersonifyToken"]   = finalToken;
                    Session["redirecttomember"] = true;
                    Session["retryAuth"]        = Convert.ToInt32(ConfigurationManager.AppSettings["PersonifyRetryCount"]);
                    LoginUsertokentico.WriteError("token for " + userName, finalToken);
                }


                var eUserData = AuthenticateCustomer(customerIdentifier, emailaddress, userName);

                if (eUserData == null)
                {
                    return;
                }

                //use master customer id as the default password
                if (customerIdentifier != null)
                {
                    var defaultPassword = customerIdentifier.Split('|')[0];
                    if (Session["PersonifyToken"] == null && !string.IsNullOrEmpty(finalToken))
                    {
                        Session["PersonifyToken"] = finalToken;
                    }
                }

                if (_wsSso != null)
                {
                    _wsSso.Dispose();
                }

                var hasToken = Request.Url.AbsoluteUri.IndexOf("ct=", StringComparison.Ordinal) > 0;
                Session["redirecttomember"] = true;

                Response.Redirect(
                    hasToken
                        ? Request.Url.AbsoluteUri.Substring(0,
                                                            Request.Url.AbsoluteUri.IndexOf("ct=", StringComparison.Ordinal) - 1)
                        : Request.Url.AbsoluteUri, true);
            }
            else
            {
                if (Session["LoginAttempted"] != null)
                {
                    bool loginAttempted;
                    bool.TryParse(Session["LoginAttempted"].ToString(), out loginAttempted);
                    if (loginAttempted)
                    {
                        Session["OpenLoginBox"] = true;
                        Session.Remove("LoginAttempted");
                    }
                }
            }
        }
        else
        {
            bool flagpersonifyMember = false;
            //if logged in as admin user  keep the userlogged in
            /// If personify token is expired logout user
            ///
            if (CMS.Membership.AuthenticationHelper.IsAuthenticated())
            {
                UserInfo userdata =
                    CMS.Membership.UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserName);

                DataTable dt = UserInfoProvider.GetUserRoles(userdata);

                if (dt.Rows.Count > 0 && dt != null)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["RoleName"].ToString().ToLower().Contains("peronifyuser"))
                        {
                            flagpersonifyMember = true;
                        }
                    }
                }

                ///if personify key is null or empty
                ///
                if (flagpersonifyMember)
                {
                    string tokenReturn = null;
                    if (Session[PersonifySessionKey] != null)
                    {
                        tokenReturn = this.ValidateCustomerToken(Session[PersonifySessionKey].ToString());
                    }

                    if ((Session[PersonifySessionKey] == null) || tokenReturn == null)
                    {
                        /* Response.Redirect(
                         * Request.ServerVariables["PATH_INFO"] + "?action=logout&returnurl=" +
                         * Server.UrlEncode(Request.Url.AbsoluteUri), true);*/

                        //logout user
                        if (Session["userClass"] != null && Session["userClass"] != "")
                        {
                            userinfo ui = (userinfo)Session["userClass"];
                            objKenticoService.Logout(ui.username);
                            System.Web.Security.FormsAuthentication.SignOut();
                            HttpContext.Current.Response.Cookies["ASPXFORMSAUTH"].Expires = DateTime.Now.AddYears(-1);


                            Response.Redirect("/logout.aspx");
                        }
                    }
                }
            }
        }
    }
Пример #4
0
    private void CheckSsoToken()
    {
        //  var userApi = new UserAPI();
        bool loggedin = objKenticoService.CheckLoginUser("");

        if (!loggedin)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ct"]))
            {
                lblMessage.Text = Request.QueryString["ct"];
                //  Ektron.Cms.Instrumentation.Log.WriteError(Request.QueryString["ct"]);
                var customerToken = Request.QueryString["ct"];
                ////
                Session["cuctomerReturnToken"] = customerToken;
                var decryptedToken = DecryptCustomerToken(customerToken);
                // Ektron.Cms.Instrumentation.Log.WriteError(decryptedToken);
                Session["OpenLoginBox"] = true;

                var finalToken = "";
                if (decryptedToken != "")
                {
                    finalToken = ValidateCustomerToken(decryptedToken);
                }

                var    customerIdentifier = "";
                string emailaddress       = null;
                string userName           = null;

                if (finalToken != "")
                {
                    customerIdentifier          = ValidateUser(finalToken, ref emailaddress, ref userName);
                    Session["PersonifyToken"]   = finalToken;
                    Session["redirecttomember"] = true;

                    LoginUsertokentico.WriteError("token for " + userName, finalToken);
                    if (string.IsNullOrEmpty(customerIdentifier))
                    {
                        //Response.Redirect("http://rapstst75.ebiz.uapps.net/Home/RegisterCustomer.aspx?Email=" +
                        //                  emailaddress + "&returnurl=" +
                        //                  "http://ek9-raps.syscomservices.com/sso_test.aspx");
                    }
                }


                var eUserData = AuthenticateCustomer(customerIdentifier, emailaddress, userName);

                if (eUserData == null)
                {
                    return;
                }

                //use master customer id as the default password
                if (customerIdentifier != null)
                {
                    var defaultPassword = customerIdentifier.Split('|')[0];

                    // var result = MyProvider.ValidateUser(eUserData.Username, defaultPassword);

                    if (Session["PersonifyToken"] == null && !string.IsNullOrEmpty(finalToken))
                    {
                        Session["PersonifyToken"] = finalToken;
                    }
                }

                if (_wsSso != null)
                {
                    _wsSso.Dispose();
                }

                var hasToken = Request.Url.AbsoluteUri.IndexOf("ct=", StringComparison.Ordinal) > 0;
                Session["redirecttomember"] = true;

                Response.Redirect(
                    hasToken
                        ? Request.Url.AbsoluteUri.Substring(0,
                                                            Request.Url.AbsoluteUri.IndexOf("ct=", StringComparison.Ordinal) - 1)
                        : Request.Url.AbsoluteUri, true);
            }
            else
            {
                if (Session["LoginAttempted"] != null)
                {
                    bool loginAttempted;
                    bool.TryParse(Session["LoginAttempted"].ToString(), out loginAttempted);
                    if (loginAttempted)
                    {
                        Session["OpenLoginBox"] = true;
                        Session.Remove("LoginAttempted");
                    }
                }
            }
        }
        else
        {
            bool flagpersonifyMember = false;
            //if logged in as admin user  keep the userlogged in
            /// If personify token is expired logout user
            ///
            if (CMS.Membership.AuthenticationHelper.IsAuthenticated())
            {
                UserInfo userdata =
                    CMS.Membership.UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserName);

                DataTable dt = UserInfoProvider.GetUserRoles(userdata);

                if (dt.Rows.Count > 0 && dt != null)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["RoleName"].ToString().ToLower().Contains("peronifyuser"))
                        {
                            flagpersonifyMember = true;
                        }
                    }
                }

                ///if personify key is null or empty
                ///
                if (flagpersonifyMember)
                {
                    string tokenReturn = null;
                    if (Session[PersonifySessionKey] != null)
                    {
                        tokenReturn = this.ValidateCustomerToken(Session[PersonifySessionKey].ToString());
                    }

                    if (Session[PersonifySessionKey] == null)//|| tokenReturn == null)
                    {
                        /* Response.Redirect(
                         * Request.ServerVariables["PATH_INFO"] + "?action=logout&returnurl=" +
                         * Server.UrlEncode(Request.Url.AbsoluteUri), true);*/

                        //logout user
                        if (Session["userClass"] != null && Session["userClass"] != "")
                        {
                            /* userinfo ui = (userinfo)Session["userClass"];  //Session["userClass"];
                             * objKenticoService.Logout(ui.username);
                             * System.Web.Security.FormsAuthentication.SignOut();
                             * HttpContext.Current.Response.Cookies["ASPXFORMSAUTH"].Expires = DateTime.Now.AddYears(-1);
                             *
                             */
                            // Response.Redirect("/logout.aspx");
                        }
                    }
                }
            }
        }
    }