Beispiel #1
0
        public UserState GetUserState(string username)
        {
            string credfile = Path.Combine(credentialpath, SafeFileString(username) + ".cred");

            if (File.Exists(credfile))
            {
                var credentials = CompanionAppCredentials.Load(credfile);
                return(credentials.IsAccessRefreshTokenPresent ? UserState.HasLoggedInWithCredentials : UserState.HasLoggedIn);
            }
            else
            {
                return(UserState.NeverLoggedIn);
            }
        }
Beispiel #2
0
 public static CompanionAppCredentials Load(string filepath)
 {
     try
     {
         string json = File.ReadAllText(filepath);
         JToken tk   = JToken.Parse(json);
         CompanionAppCredentials credentials = JTokenExtensions.ToObject <CompanionAppCredentials>(tk);
         credentials.savedPath = filepath;
         return(credentials);
     }
     catch
     {
         return(new CompanionAppCredentials()
         {
             savedPath = filepath
         });
     }
 }
Beispiel #3
0
        // login for user, we can login over another user
        // returns true if operating okay (may be performing user login) or false if can't log in

        public bool LogIn(string username)
        {
            if (!ClientIDAvailable)                                 // must have an ID, else service is disabled
            {
                return(false);
            }

            if (username == User && CurrentState != State.LoggedOut)     // if logged in to the same user
            {
                return(true);
            }

            string credfile = Path.Combine(credentialpath, SafeFileString(username) + ".cred");

            Credentials = CompanionAppCredentials.Load(credfile);

            User = username;

            CurrentState  = State.LoggedOut;        // clear state back to logged out
            cachedProfile = null;                   // empty any cached profile

            try
            {
                RefreshToken();
            }
            catch (EliteDangerousCompanionWebException ws)                 // web exceptions, they happen. don't lost the refresh token over it
            {
                System.Diagnostics.Debug.WriteLine(ws);
                return(false);
            }
            catch (Exception)
            {
                AskForLogin();          // and login
            }

            return(true);        // everything is ok, either we have logged in, or we are in the process of asking the user for a login
        }