示例#1
0
文件: User.cs 项目: rocketeerbkw/DNA
        /// <summary>
        /// Method that tries to login in the user with a cookie.
        /// Requires Profile API to be initialised.
        /// </summary>
        /// <param name="signInComponent">Initialised SignIn Component</param>
        /// <param name="autoLogIn">Indicates whether user login was performed.</param>
        /// <param name="migrated">Indicate whether the user is migrating. This happens when we can't find the identity userid, but we can the legacy sso id</param>
        private void TryLoginUser(ref IDnaIdentityWebServiceProxy signInComponent, ref bool autoLogIn, ref bool migrated)
        {
            autoLogIn = false;
            _userID = 0;
                
            // Check to see if they are logged in
            _userLoggedIn = signInComponent.IsUserLoggedIn;
            if (!_userLoggedIn)
            {
                try
                {
                    // Try to log them into the service
                    _userLoggedIn = signInComponent.LoginUser();
                    autoLogIn = _userLoggedIn;
                }
                catch (ProfileAPIException ex)
                {
                    // Catch any Profile Exceptions, but don't throw as we can carry on without the user being logged in
                    InputContext.Diagnostics.WriteWarningToLog("User", "Failed to log in user");
                    InputContext.Diagnostics.WriteExceptionToLog(ex);
                    _userLoggedIn = false;
                }
                //catch (MySql.Data.MySqlClient.MySqlException ex)
                //{
                //    InputContext.Diagnostics.WriteWarningToLog("User", "Failed to log in user");
                //    InputContext.Diagnostics.WriteExceptionToLog(ex);
                //    _userLoggedIn = false;
                //}
            }

            _loginName = signInComponent.LoginName;

            // Now get the userid if we logged them in ok
            if (_userLoggedIn)
            {
                GetDnaUserIDFromSignInID(signInComponent, "");
                if (_userID == 0 && signInComponent.SignInSystemType == SignInSystem.Identity)
                {
                    if (signInComponent.DoesAttributeExistForService(InputContext.CurrentSite.SSOService, "legacy_user_id"))
                    {
                        int legacyID = 0;
                        if (int.TryParse(signInComponent.GetUserAttribute("legacy_user_id"), out legacyID))
                        {
                            GetDnaUserIDFromSignInID(signInComponent, legacyID.ToString());
                            migrated = true;
                        }
                    }
                }
            }
        }