Viewing a response to: @steempytutorials/integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website
Thank you for wondefull tuts. I managed to follow Part 1 and got the login for the user. Now trying to follow this tut but I find it hard to find where I need to add these to make it work. Have to say total noob here.
author | freetissues |
---|---|
permlink | re-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t104221224z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-07-31 10:42:24 |
last_update | 2018-07-31 10:42:24 |
depth | 1 |
children | 2 |
last_payout | 2018-08-07 10:42:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 218 |
author_reputation | 475,604,110,215 |
root_title | "Integrate Steemconnect V2 User Authorisation Into Any WordPress Website" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,623,150 |
net_rshares | 1,151,562,821 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
ceruleanblue | 0 | 1,151,562,821 | 100% |
Glad to hear that. You can place the code inside a special file, lets say authentication.php and then include this file into the header.php. Basically, the page where the user will get redirectes back to. The uri you set in the link. That page will need to have the file included
author | juliank |
---|---|
permlink | re-freetissues-re-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t115827590z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-07-31 11:58:24 |
last_update | 2018-07-31 11:58:24 |
depth | 2 |
children | 0 |
last_payout | 2018-08-07 11:58:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.076 HBD |
curator_payout_value | 0.025 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 280 |
author_reputation | 117,823,071,447,502 |
root_title | "Integrate Steemconnect V2 User Authorisation Into Any WordPress Website" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,629,594 |
net_rshares | 60,689,117,289 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
freetissues | 0 | 60,689,117,289 | 100% |
To give a bit more detail. I have a file authentication.php ``` <?php if (isset($_GET['code'])) { // Params for POST request $data = array( 'code' => $_GET['code'], 'client_secret' => SC_CLIENT_SECRET ); $payload = json_encode($data); // Prepare new cURL resource $ch = curl_init('https://steemconnect.com/api/oauth2/token'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // Set HTTP Header for POST request curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload)) ); // Submit the POST request $result = curl_exec($ch); // Close cURL session handle curl_close($ch); $json = json_decode($result); $date = date("Y/m/d H:G:s", time() + $json->expires_in); // Add tokens to the database global $wpdb; $wpdb->query("INSERT INTO `steem_authorization` (`id`, `access_token`, " . "`user_login`, `expires_in`, `refresh_token`) VALUES (NULL, " . "'" . $json->access_token . "', '" . $json->username ."', '" . $date . "', '" . $json->refresh_token ."') ON DUPLICATE KEY UPDATE " . "`user_login`='" . $json->username ."';"); } ?> ``` The client secret, I set that in wp-config.php ``` 'client_secret' => SC_CLIENT_SECRET ``` Then inside the template file of the page I want to add a authorise button I have added the following code: ``` // import steemconnet authentication include 'authenticate.php'; // see if current user is logged in and has authenticated voting // permissions in the database global $wpdb; $current_user = wp_get_current_user(); ``` This includes the file and get the username. Then lasty I check if the user has already authorised the app if not it shows a button to do so. ``` echo '<div>'; // Check if user is logged in if ($current_user->user_login == ''){ echo '<div align="center"><br><h1>You need to <a href="https://ste' . 'emautomated.eu/wp-login.php?action=wordpress_social_authenticate&' . 'mode=login&provider=Steemconnect&redirect_to=' . get_permalink() . '">log in</a></h1></div>'; } else { // Check if logged in user has authorised the app $results = $wpdb->get_results('SELECT * FROM `steem_authorization` ' . 'WHERE `user_login` = "' . $current_user->user_login . '"'); if (count($results) == 0){ echo '<div align="center"><h1><br>Authorize <font color=' . '"blue">@steemautomated</font> to vote for you.</h1><br><a ' . 'class="maxbutton-1 maxbutton maxbutton-steemconnect" href=' . '"https://steemconnect.com/oauth2/authorize?client_id=' . 'steemautomated&redirect_uri=' . get_permalink() .'&response_' . 'type=code&scope=offline,vote"><span class="mb-text">' . 'Authorize</span></a></div><br>'; } } echo '</div>'; ```
author | steempytutorials |
---|---|
permlink | re-freetissues-re-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t135136668z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-07-31 13:51:36 |
last_update | 2018-07-31 13:51:36 |
depth | 2 |
children | 0 |
last_payout | 2018-08-07 13:51:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.079 HBD |
curator_payout_value | 0.025 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,976 |
author_reputation | 31,094,047,689,691 |
root_title | "Integrate Steemconnect V2 User Authorisation Into Any WordPress Website" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,640,643 |
net_rshares | 61,729,502,157 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
freetissues | 0 | 61,729,502,157 | 100% |