예제 #1
0
        /// <summary>
        /// Attempt to login to the mod repository.
        /// </summary>
        /// <returns><c>true</c> if the login was successful;
        /// <c>false</c> otherwise.</returns>
        public bool Login()
        {
            ErrorMessage = null;
            EnvironmentInfo.Settings.RepositoryUsernames[ModRepository.Id] = Username;
            Dictionary <string, string> dicAuthTokens = null;

            try
            {
                if (!ModRepository.Login(Username, Password, out dicAuthTokens))
                {
                    ErrorMessage = "The given login information is invalid.";
                    return(false);
                }
            }
            catch (RepositoryUnavailableException e)
            {
                ErrorMessage = e.Message;
                return(false);
            }
            if (StayLoggedIn)
            {
                EnvironmentInfo.Settings.RepositoryAuthenticationTokens[ModRepository.Id] = new KeyedSettings <string>(dicAuthTokens);
            }
            else
            {
                EnvironmentInfo.Settings.RepositoryAuthenticationTokens.Remove(ModRepository.Id);
            }
            EnvironmentInfo.Settings.Save();
            return(true);
        }
        /// <summary>
        /// Attempt to login to the mod repository.
        /// </summary>
        /// <returns><c>true</c> if the login was successful;
        /// <c>false</c> otherwise.</returns>
        public bool Login()
        {
            ErrorMessage = null;
            EnvironmentInfo.Settings.RepositoryUsernames[ModRepository.Id] = Username;
            Dictionary <string, string> dicAuthTokens = null;

            try
            {
                if (!ModRepository.Login(Username, Password, out dicAuthTokens))
                {
                    ErrorMessage = "Invalid login. Either your firewall is blocking NMM or the login server is down.";
                    return(false);
                }
            }
            catch (RepositoryUnavailableException e)
            {
                ErrorMessage = e.Message;
                return(false);
            }
            if (StayLoggedIn)
            {
                EnvironmentInfo.Settings.RepositoryAuthenticationTokens[ModRepository.Id] = new KeyedSettings <string>(dicAuthTokens);
            }
            else
            {
                EnvironmentInfo.Settings.RepositoryAuthenticationTokens.Remove(ModRepository.Id);
            }
            EnvironmentInfo.Settings.Save();
            return(true);
        }