Пример #1
0
 //
 // Sign out and clear fields and table
 //
 private void signout_btn_Click(object sender, EventArgs e)
 {
     _oauth = null;
     this.client_id_text.Text     = null;
     this.client_secret_text.Text = null;
     this.email_text.Text         = null;
     this.pwd_text.Text           = null;
     this.profile_box.Items.Clear();
     this.profile_image.ImageLocation = null;
     this.signin_btn.Enabled          = true;
     this.signout_btn.Enabled         = false;
     this.api_ws_btn.Enabled          = false;
     this.api_file_btn.Enabled        = false;
     this.api_task_btn.Enabled        = false;
     this.tp_datagridview.Columns.Clear();
     this.tp_datagridview.Refresh();
     showMessage("Please sign in.");
 }
Пример #2
0
        //
        // Sign in to TeamPlatform and get the user profile
        //
        private void signin_btn_Click(object sender, EventArgs e)
        {
            string client_id     = this.client_id_text.Text;
            string client_secret = this.client_secret_text.Text;
            string email         = this.email_text.Text;
            string pwd           = this.pwd_text.Text;

            //
            // OAuth2 Client ID and Secret.
            //
            // If don't have a client ID/Secret, you need to register a new client app
            //
            // (1) Please sing into TeamPlatform account on the Web and go to Settings->API tab
            // https://teamplatform.com/settings#tab-api-s
            //
            // (2) Register a new client. Application URL and Redirect URI should have full addresses staring with http:// or https://
            //
            // (3) Copy and paste newly generated client ID/Secret in the form or the code below.
            //
            //client_id = "";
            //client_secret = "";
            //

            string error_msg = null;

            showMessage("Connecting ...");

            //
            // Authorizing - password method
            //
            if (is_blank(client_id) || is_blank(client_secret) || is_blank(email) || is_blank(pwd))
            {
                showMessage("Failed to sign in - info missing.");
                return;
            }
            _oauth = new tpOAuth2();
            bool authorized = _oauth.tpGetAuthorization(client_id, client_secret, email, pwd, out error_msg);

            if (!authorized)
            {
                showMessage(error_msg);
                return;
            }
            showMessage("Successfully signed in.");

            //
            // Get the user profile
            //
            bool getUser = _oauth.tpGetProfile(out error_msg);

            if (!getUser)
            {
                showMessage(error_msg);
                return;
            }
            this.profile_box.Items.Clear();
            this.profile_box.Items.AddRange(_oauth.User.user_info_arr());
            this.profile_image.ImageLocation = _oauth.User.picture;

            // Update button status
            this.signin_btn.Enabled   = false;
            this.signout_btn.Enabled  = true;
            this.api_ws_btn.Enabled   = true;
            this.api_file_btn.Enabled = true;
            this.api_task_btn.Enabled = true;
        }
Пример #3
0
 //
 // Sign out and clear fields and table
 //
 private void signout_btn_Click(object sender, EventArgs e)
 {
     _oauth = null;
     this.client_id_text.Text = null;
     this.client_secret_text.Text = null;
     this.email_text.Text = null;
     this.pwd_text.Text = null;
     this.profile_box.Items.Clear();
     this.profile_image.ImageLocation = null;
     this.signin_btn.Enabled = true;
     this.signout_btn.Enabled = false;
     this.api_ws_btn.Enabled = false;
     this.api_file_btn.Enabled = false;
     this.api_task_btn.Enabled = false;
     this.tp_datagridview.Columns.Clear();
     this.tp_datagridview.Refresh();
     showMessage("Please sign in.");
 }
Пример #4
0
        //
        // Sign in to TeamPlatform and get the user profile
        //
        private void signin_btn_Click(object sender, EventArgs e)
        {
            string client_id = this.client_id_text.Text;
            string client_secret = this.client_secret_text.Text;
            string email = this.email_text.Text;
            string pwd = this.pwd_text.Text;

            //
            // OAuth2 Client ID and Secret.
            //
            // If don't have a client ID/Secret, you need to register a new client app
            //
            // (1) Please sing into TeamPlatform account on the Web and go to Settings->API tab
            // https://teamplatform.com/settings#tab-api-s
            //
            // (2) Register a new client. Application URL and Redirect URI should have full addresses staring with http:// or https://
            //
            // (3) Copy and paste newly generated client ID/Secret in the form or the code below.
            //
            //client_id = "";
            //client_secret = "";
            //

            string error_msg = null;

            showMessage("Connecting ...");

            //
            // Authorizing - password method
            //
            if (is_blank(client_id) || is_blank(client_secret) || is_blank(email) || is_blank(pwd))
            {
                showMessage("Failed to sign in - info missing.");
                return;
            }
            _oauth = new tpOAuth2();
            bool authorized = _oauth.tpGetAuthorization(client_id, client_secret, email, pwd, out error_msg);
            if (!authorized)
            {
                showMessage(error_msg);
                return;
            }
            showMessage("Successfully signed in.");

            //
            // Get the user profile
            //
            bool getUser = _oauth.tpGetProfile(out error_msg);
            if (!getUser)
            {
                showMessage(error_msg);
                return;
            }
            this.profile_box.Items.Clear();
            this.profile_box.Items.AddRange(_oauth.User.user_info_arr());
            this.profile_image.ImageLocation = _oauth.User.picture;

            // Update button status
            this.signin_btn.Enabled = false;
            this.signout_btn.Enabled = true;
            this.api_ws_btn.Enabled = true;
            this.api_file_btn.Enabled = true;
            this.api_task_btn.Enabled = true;
        }