示例#1
0
文件: User.cs 项目: rocketeerbkw/DNA
        /// <summary>
        /// Initialises profile connection.
        /// </summary>
        /// <param name="cookie">Dna Cookie to login with</param>
        /// <param name="signInComponent">Initialised ProfileAPI</param>
        private bool InitialiseProfileAPI(DnaCookie cookie, ref IDnaIdentityWebServiceProxy signInComponent)
        {
            InputContext.Diagnostics.WriteTimedEventToLog("SSO", "Start");
            DateTime timer = DateTime.Now; 

            // Set the current user. If this returns false, it means the user was not signed in correctly
            string decodedCookie = cookie.Value;

            // Get a profile connection
            if (signInComponent.SignInSystemType == SignInSystem.Identity)
            {
                signInComponent.SetService(InputContext.CurrentSite.IdentityPolicy);
            }
            else
            {
                signInComponent.SetService(InputContext.CurrentSite.SSOService);
            }

            InputContext.Diagnostics.WriteTimedEventToLog("SSO","End");

            // Check to see if the service was set ok before calling any user functions
            if (!signInComponent.IsServiceSet)
            {
                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Service not set!!!");
                return false;
            }

            string secureCookie = "";
            if (InputContext.GetCookie("IDENTITY-HTTPS") != null)
            {
                secureCookie = InputContext.GetCookie("IDENTITY-HTTPS").Value;
            }

            bool userSet = signInComponent.TrySecureSetUserViaCookies(decodedCookie, secureCookie) || signInComponent.IsUserSignedIn;

            InputContext.IsSecureRequest = signInComponent.IsSecureRequest;
            InputContext.Diagnostics.WriteToLog("---** InputContext.IsSecureRequest **---", InputContext.IsSecureRequest.ToString());
            if (!userSet)
            {
                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Set user with cookie failed!!! - " + decodedCookie);
                if (secureCookie.Length > 0)
                {
                    InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Set user with secure cookie failed!!! - " + secureCookie);
                }

                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Timing Info: "+signInComponent.GetLastTimingInfo());

                return false;
            }

            Statistics.AddIdentityCallDuration(TimeSpan.FromTicks(DateTime.Now.Ticks - timer.Ticks).Milliseconds);

            return true;
        }