Add SteemConnect V2 to SteemThink to Verify Users
Added New Features
What feature did I add?
I added the SteemConnect V2 to SteemThink to let this site has the ability to verify the users. This is a very basic and very important function.
How did I implement it?
I use SC2-SDK and AngularJs to implement this function. I also reference the example on github: https://cnsteem.github.io/sc2-angular/.
After I successd get the Access Token from SteemConnect V2, I saved it into cookie. In this way all pages in this site can use this Access Token in a very convenient way.
The most important part of my code is:
if(sc2.accessToken == null || sc2.accessToken == '') { sc2.init({ app: 'steemthink.com', callbackURL: 'http://localhost/callback.html', scope: ['vote', 'comment'] }); } angular.module('app', ['ipCookie']) .config(['$locationProvider', function($locationProvider){ $locationProvider.html5Mode(true); }]) .controller('Main', function($scope, ipCookie) { $scope.loading = false; $scope.parentAuthor = 'skenan'; $scope.parentPermlink = 'steem-connect-v2'; $scope.accessToken = ipCookie('st_access_token'); $scope.loginURL = sc2.getLoginURL(); if ($scope.accessToken) { sc2.setAccessToken($scope.accessToken); sc2.me(function (err, result) { console.log('/me', err, result); if (!err) { $scope.user = result.account; $scope.metadata = JSON.stringify(result.user_metadata, null, 2); $scope.$apply(); } }); } $scope.isAuth = function() { return !!$scope.user; }; $scope.loadComments = function() { steem.api.getContentReplies($scope.parentAuthor, $scope.parentPermlink, function(err, result) { if (!err) { $scope.comments = result.slice(-5); $scope.$apply(); } }); }; $scope.comment = function() { $scope.loading = true; var permlink = steem.formatter.commentPermlink($scope.parentAuthor, $scope.parentPermlink); sc2.comment($scope.parentAuthor, $scope.parentPermlink, $scope.user.name, permlink, '', $scope.message, '', function(err, result) { console.log(err, result); $scope.message = ''; $scope.loading = false; $scope.$apply(); $scope.loadComments(); }); }; $scope.vote = function(author, permlink, weight) { sc2.vote($scope.user.name, author, permlink, weight, function (err, result) { if (!err) { alert('You successfully voted for @' + author + '/' + permlink); console.log('You successfully voted for @' + author + '/' + permlink, err, result); $scope.loadComments(); } else { console.log(err); } }); }; $scope.updateUserMetadata = function(metadata) { sc2.updateUserMetadata(metadata, function (err, result) { if (!err) { alert('You successfully updated user_metadata'); console.log('You successfully updated user_metadata', result); if (!err) { $scope.user = result.account; $scope.metadata = JSON.stringify(result.user_metadata, null, 2); $scope.$apply(); } } else { console.log(err); } }); }; $scope.logout = function() { sc2.revokeToken(function (err, result) { console.log('You successfully logged out', err, result); delete $scope.user; delete $scope.accessToken; $scope.$apply(); }); }; }) .controller('SetCookies', ['$scope', '$location', 'ipCookie', function($scope, $location, ipCookie) { $scope.loading = false; $scope.accessToken = $location.search().access_token; $scope.expiresIn = $location.search().expires_in; if ($scope.accessToken) { sc2.setAccessToken($scope.accessToken); //get the details of an account //set the cookie ipCookie('st_access_token', $scope.accessToken, {expirationUnit: 'seconds', expires: $scope.expiresIn * 1}); sc2.me(function (err, result) { console.log('/me', err, result); if (!err) { $scope.user = result.account; $scope.metadata = JSON.stringify(result.user_metadata, null, 2); $scope.$apply(); } }); } $scope.isAuth = function() { return !!$scope.user; }; }]);
In the code upwards, I inited the SC2, and also added the comment, vote, loadcomment methods.
What is SteemThink?
- SteemThink is a knowledge sharing platform based on Steem block chain. Users communicate in the form of questions and answers. Everyone can upvote valuable answers, and can follow anyone with knowledge.
- SteemThink is an open source project. We believe that through github everyone can participate in by collaborating. You can be a programmer, designer, marketer, etc.
- SteemThink is a non-profit organization. All of the donations and potential income will be completely used for the project's operation expenses & development expenses.
- SteemThink's expectation is to have more people join this exciting, passionate ecosystem of Steem.
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @rileyge I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Your Post Has Been Featured on @Resteemable!
Feature any Steemit post using resteemit.com!
How It Works:
1. Take Any Steemit URL
2. Erase
https://
3. Type
re
Get Featured Instantly � Featured Posts are voted every 2.4hrs
Join the Curation Team Here | Vote Resteemable for Witness
nice work, steem think seems like something i should get into, where do i start, what is needed on the platform right now from users?
Now this site is developing, it will be available in future.