/// <summary>
        /// Receives logout event and resets authorization vars.
        /// </summary>
        public void MainForm_LogoutReady()
        {
            // Reset authorization, form controls and values
            saluteLabel.Text = "";
            DisableButtons();
            ResetAccountValues();
            _authorization = null;

            this.Cursor = Cursors.Default;
        }
Пример #2
0
 /// <summary>
 /// Browser navigation event.
 /// </summary>
 private void loginBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
 {
     try
     {
         string accessToken = GetAccessTokenFromUrl("access_token", e.Url.ToString());
         // If navigation url includes an access token, this is our page!
         if (accessToken != "")
         {
             DateTime      expirationDate = DateTime.Now.AddSeconds(Convert.ToInt32(GetAccessTokenFromUrl("expires_in", e.Url.ToString())));
             Int32         userId         = Convert.ToInt32(GetAccessTokenFromUrl("user_id", e.Url.ToString()));
             OAuthResponse response       = new OAuthResponse(accessToken, expirationDate, userId);
             FirstForm.MainForm_LoginReady(response);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message + "___" + ex.StackTrace);
     }
 }
        /// <summary>
        /// Receives login event and inits authorization vars.
        /// </summary>
        public void MainForm_LoginReady(OAuthResponse response)
        {
            try
            {
                // Set app authorization
                _authorization = response;

                // Get user info and set salute label text
                UsersHelper uh = new UsersHelper();
                uh.AccessToken = _authorization.AccessToken;
                User user = uh.GetUser(response.UserId);
                saluteLabel.Text = "Hi, " + user.FirstName + " " + user.LastName + " (" + user.Email + ")";

                // Hide login form and enable main form buttons
                _loginForm.Hide();
                EnableControlButtons();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Login failure: " + ex.Message);
            }
        }