Steemautomated: 0.0.2 - Front-End With Steemconnect Integration

in utopian-io •  6 months ago



Original post



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


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.

Screenshot 2018-07-24 18.50.48.png



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="' . $login_redirect_to . '">'.$login_text.'</a>';


Screenshot 2018-07-24 18.52.56.png

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.

Screenshot 2018-07-24 18.52.37.png

Screenshot 2018-07-24 18.54.23.png

// 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' .
    '' .
    '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=' .
                '"' .
                'steemautomated&redirect_uri=' . get_permalink() .'&response_' .
                'type=code&scope=offline,vote"><span class="mb-text">' .
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.
Screenshot 2018-07-24 18.54.46.png

  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('');
    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

    $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.
Screenshot 2018-07-24 18.51.30.png

Each user can easily add and alter any rules.
Screenshot 2018-07-24 18.51.38.png

Inline editing is also supported
Screenshot 2018-07-24 18.51.57.png

GitHub Account

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thanks for the contribution, @steempytutorials! Some thoughts about this contribution:

  • Commit messages could be a lot better! Just writing something like "Front-end" for two commits is not at all descriptive, and obviously impossible to distinguish - I would recommend checking out these guidelines or any other guidelines about "how to write good commit messages".
  • It's always great if you can make it clear to us which commits were made explicitly by you and which were auto-generated. For example, this commit has 1,234,151 additions! You could make separate commits for the auto-generated code and not include this in your contribution, which would make it much easier for us to review.
  • Push commits once they are done (not sure if you did this, but the relevant commits were all made pretty close to each other, which makes me think you didn't).
  • Add a licence to the repository!

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
Chat with us on Discord.

Hey @steempytutorials
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord

Vote for Utopian Witness!