Steemautomated: 0.0.2 - Front-End With Steemconnect Integration
Repository
new https://github.com/Juless89/steemautomated
old https://github.com/Juless89/fully-automated-steemvoter
Original post
https://steemit.com/utopian-io/@steempytutorials/fully-automated-steem-voter
Website
Note
Voting is not yet active. The backend code has to be updated to work with Steemconnect access tokens. This will be done in the next update.
New Features
Front-end
All new front-end with Steemconnect authentication. Created with wordpress, freely available plugins and theme. Several important changes were made to the plugins and added to allow for Steemconnect integration.
Steemconnect
Authentication
Wordpress social login is used to authenticate users. This branch has enabled Steemconnect. The following line was changed so that a new user will have the exact name as their Steem account.
$this->user->profile->displayName = $data->_id;
To only allow authentication via Steemconnect all login buttons direct directly to the Wordpress social login plugin instead of a login screen. The plugin then redirects to Steemconnect, which redirects back to the website, where the plugin deals with the authentication. Another plugin login-logout is used which was altered to direct to wordpress social login.
//wp_loginout( $redirect_to_self );
if ( ! is_user_logged_in() ){
echo '"item_login">';
echo '<a href="https://steemautomated.eu/wp-login.php?action=wordpress_social_authenticate&mode=login&provider=Steemconnect&redirect_to=' . $login_redirect_to . '">'.$login_text.'</a>';
}
Obtaining offline voting permissions
In order to vote for users offline voting permissions have to be obtained. First the users is checked to be logged in. If not, the user is request to do so. When the user is logged username corresponds to their Steem account. This account is looked up in the steem_authorization
table where the access and refresh tokens are stored. The user is then requested to authorise @steemautomated to perform offline voting.
// 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();
echo '<div>';
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 {
$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>';
Obtaining offline voting permissions is done with a POST request on the server. First performing a GET type=code&scope=offline,vote
request to Steemconnect returns a code, this code is then used to obtain the access_token and refresh_token. The tokens are stored into the database with the date when the access_token expires.
<?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 ."';");
}
?>
Dynamic tables
The voting and trailing rules are stored in customisable tables.
Each user can easily add and alter any rules.
Inline editing is also supported
Thanks for the contribution, @steempytutorials! Some thoughts about this contribution:
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hey @steempytutorials
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!