Permissions

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-05 14:30:02 -03:00
commit 9379e6e574
5 changed files with 130 additions and 68 deletions

View file

@ -22,44 +22,72 @@
</div> </div>
<div class="text-center m10b"> <div class="text-center m10b">
<img src="img/glidera-logo.png" ng-click="glidera.update(index.glideraToken)"> <img src="img/glidera-logo.png">
</div> </div>
<div ng-if="!index.glideraToken" class="row"> <div ng-if="!index.glideraToken" class="row">
<div class="columns" ng-init="showOauthForm = false"> <div class="columns" ng-init="showOauthForm = false">
<div class="text-center" ng-show="!showOauthForm"> <div class="text-center" ng-show="!showOauthForm">
<p translate>You can buy and sell Bitcoin with a US bank account directly in Copay</p> <p translate>You can buy and sell Bitcoin with a US bank account directly in Copay.</p>
<p class="text-gray size-12">Connect your Glidera account to get started</p> <div class="m10b text-gray size-12" translate>Connect your Glidera account to get started</div>
<button <button
class="dark-gray outline round tiny" class="dark-gray outline round tiny"
ng-click="$root.openExternalLink(glidera.authenticateUrl); showOauthForm = true" translate> ng-click="$root.openExternalLink(glidera.authenticateUrl); showOauthForm = true" translate>
Connect to Glidera Connect to Glidera
</button> </button>
<a href ng-click="showOauthForm = true" class="db text-gray size-12"> <div>
Do you already have the Oauth Code? <a href ng-click="showOauthForm = true" class="text-gray size-12">
</a> Do you already have the Oauth Code?
</a>
</div>
</div> </div>
<div class="text-center" ng-show="showOauthForm"> <div class="text-center" ng-show="showOauthForm">
<p class="text-gray size-12">Paste the authorization code here</p> <p class="text-gray size-12">Paste the authorization code here</p>
<form name="oauthCode" ng-submit="glidera.submitOauthCode(code)" novalidate> <form name="oauthCodeForm" ng-submit="glidera.submitOauthCode(code)" novalidate>
<label>OAuth Code<label> <label>OAuth Code</label>
<input type="text" ng-model="code" ng-disabled="glidera.loading"> <input type="text" ng-model="code" ng-disabled="glidera.loading" required>
<input <input
class="button dark-gray outline round" class="button expand round"
type="submit" value="Get started" ng-disabled="glidera.loading"> ng-style="{'background-color':index.backgroundColor}"
type="submit" value="Get started" ng-disabled="oauthCodeForm.$invalid || glidera.loading">
</form> </form>
<div>
<a href class="size-12 text-gray" ng-click="showOauthForm = false" translate>Go back</a>
</div>
</div> </div>
</div> </div>
</div> </div>
<div ng-if="index.glideraToken" ng-init="glidera.init(index.glideraToken)">
<div class="m20t text-center" ng-if="index.glideraToken && index.glideraError">
<div class="text-warning">
<span ng-show="index.glideraError == 'Unauthorized'" translate>Could not connect with Glidera: Unauthorized</span>
<span ng-show="index.glideraError == 'Forbidden'" translate>Could not connect with Glidera: Forbidden</span>
<span ng-show="index.glideraError != ('Forbidden' && 'Unauthorized')" translate>Could not connect with Glidera</span>
</div>
<div class="m10t">
<button class="round tiny" ng-click="index.glideraToken = null; index.glideraError = null">
Request a new token
</button>
</div>
</div>
<div ng-if="index.glideraToken && index.glideraPermissions"
ng-init="glidera.update(index.glideraToken, index.glideraPermissions)">
<div class="text-center m10b">
<div class="size-12" ng-show="index.glideraEmail">{{index.glideraEmail}}</div>
<div ng-show="index.glideraPersonalInfo" class="size-12">
{{index.glideraPersonalInfo.firstName}} {{index.glideraPersonalInfo.lastName}} {{index.glideraPersonalInfo.personalInfoState}}
</div>
</div>
<div class="text-center m20b"> <div class="text-center m20b">
{{index.glideraEmail}} <br>
<a href class="text-gray" ng-click="$root.go('preferencesGlidera')"> <a href class="text-gray" ng-click="$root.go('preferencesGlidera')">
Preferences Preferences
</a> </a>
</div> </div>
<ul class="no-bullet m0 size-14"> <ul class="no-bullet m0 size-14" ng-show="index.glideraPermissions.transact">
<li class="line-b line-t p20 pointer" ng-click="$root.go('buyGlidera')"> <li class="line-b line-t p20 pointer" ng-click="$root.go('buyGlidera')">
<span translate>Buy</span> <span translate>Buy</span>
<span class="right text-gray"> <span class="right text-gray">
@ -74,33 +102,39 @@
</li> </li>
</ul> </ul>
<h4 class="title m0" translate>Activity</h4> <div ng-show="index.glideraPermissions.transaction_history">
<div ng-repeat="tx in index.glideraTxs" <h4 class="title m0" translate>Activity</h4>
ng-click="glidera.openTxModal(index.glideraToken, tx)" <div ng-show="!index.glideraTxs"
class="row collapse last-transactions-content"> class="size-12 p10 text-center text-gray" translate>
<div class="large-3 medium-3 small-3 columns"> No activity in your account
<span class="label tu radius" ng-show="tx.type == 'BUY'"
ng-style="{'background-color':index.backgroundColor}" translate>Bought</span>
<span class="label tu gray radius" ng-show="tx.type == 'SELL'" translate>Sold</span>
</div> </div>
<div ng-repeat="tx in index.glideraTxs"
<div class="large-4 medium-4 small-4 columns"> ng-click="glidera.openTxModal(index.glideraToken, tx)"
<span class="size-16"> class="row collapse last-transactions-content">
{{tx.subtotal}} {{tx.currency}} <div class="large-3 medium-3 small-3 columns">
</span> <span class="label tu radius" ng-show="tx.type == 'BUY'"
</div> ng-style="{'background-color':index.backgroundColor}" translate>Bought</span>
<div class="large-4 medium-4 small-4 columns text-right"> <span class="label tu gray radius" ng-show="tx.type == 'SELL'" translate>Sold</span>
<div class="m5t size-12 text-gray"> </div>
<time ng-if="tx.transactionDate">{{tx.transactionDate | amTimeAgo}}</time>
<div class="large-4 medium-4 small-4 columns">
<span class="size-16">
{{tx.subtotal}} {{tx.currency}}
</span>
</div>
<div class="large-4 medium-4 small-4 columns text-right">
<div class="m5t size-12 text-gray">
<time ng-if="tx.transactionDate">{{tx.transactionDate | amTimeAgo}}</time>
</div>
</div>
<div class="large-1 medium-1 small-1 columns text-right">
<i class="icon-arrow-right3 size-18"></i>
</div>
<div class="size-12 text-gray columns m5t">
<span class="text-success" ng-if="tx.status == 'COMPLETE'">Completed</span>
<span class="text-info" ng-if="tx.status == 'PROCESSING'">Processing</span>
<span class="text-warning" ng-if="tx.status == 'ERROR'">Error</span>
</div> </div>
</div>
<div class="large-1 medium-1 small-1 columns text-right">
<i class="icon-arrow-right3 size-18"></i>
</div>
<div class="size-12 text-gray columns m5t">
<span class="text-success" ng-if="tx.status == 'COMPLETE'">Completed</span>
<span class="text-info" ng-if="tx.status == 'PROCESSING'">Processing</span>
<span class="text-warning" ng-if="tx.status == 'ERROR'">Error</span>
</div> </div>
</div> </div>

View file

@ -1,21 +1,11 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('glideraController', angular.module('copayApp.controllers').controller('glideraController',
function($scope, $timeout, $modal, profileService, configService, storageService, glideraService) { function($scope, $timeout, $modal, applicationService, profileService, configService, storageService, glideraService) {
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
this.authenticateUrl = glideraService.getOauthCodeUrl(); this.authenticateUrl = glideraService.getOauthCodeUrl();
this.update = function(token) {
var self = this;
glideraService.getTransactions(token, function(error, txs) {
self.txs = txs;
});
glideraService.getEmail(token, function(error, data) {
self.email = data.email;
});
};
this.submitOauthCode = function(code) { this.submitOauthCode = function(code) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var self = this; var self = this;
@ -24,9 +14,9 @@ angular.module('copayApp.controllers').controller('glideraController',
glideraService.getToken(code, function(error, data) { glideraService.getToken(code, function(error, data) {
if (data && data.access_token) { if (data && data.access_token) {
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() { storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
$scope.$emit('Local/GlideraTokenUpdated'); $scope.$emit('Local/GlideraTokenUpdated', data.access_token);
$timeout(function() { $timeout(function() {
self.loading = false; self.loading = null;
$scope.$apply(); $scope.$apply();
}, 100); }, 100);
}); });

View file

@ -114,8 +114,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setSpendUnconfirmed(); self.setSpendUnconfirmed();
self.glideraToken = null; self.glideraToken = null;
self.glideraTxs = null; self.glideraPermissions = null;
self.glideraEmail = null; self.glideraEmail = null;
self.glideraPersonalInfo = null;
self.glideraTxs = null;
$timeout(function() { $timeout(function() {
self.hasProfile = true; self.hasProfile = true;
@ -848,22 +850,55 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}), 'name'); }), 'name');
}; };
self.initGlidera = function() { self.initGlidera = function(accessToken) {
if (self.isShared) return; if (self.isShared) return;
storageService.getGlideraToken(self.network, function(err, val) {
if (err || !val) return; var getToken = function(cb) {
if (accessToken) {
cb(null, accessToken);
} else {
storageService.getGlideraToken(self.network, cb);
}
};
getToken(function(err, accessToken) {
if (err || !accessToken) return;
else { else {
self.glideraToken = val; self.glideraToken = accessToken;
glideraService.getTransactions(val, function(error, txs) { glideraService.getAccessTokenPermissions(self.glideraToken, function(err, p) {
self.glideraTxs = txs; if (err) {
}); self.glideraError = err;
glideraService.getEmail(val, function(error, data) { $log.error(err);
self.glideraEmail = data.email; }
else {
self.glideraPermissions = p;
self.updateGlidera(accessToken, p);
}
}); });
} }
}); });
}; };
self.updateGlidera = function(accessToken, permissions) {
if (!accessToken || !permissions) return;
if (permissions.view_email_address) {
glideraService.getEmail(accessToken, function(err, data) {
self.glideraEmail = data.email;
});
}
if (permissions.personal_info) {
glideraService.getPersonalInfo(accessToken, function(err, data) {
self.glideraPersonalInfo = data;
});
}
if (permissions.transaction_history) {
glideraService.getTransactions(accessToken, function(err, data) {
self.glideraTxs = data;
});
}
};
// UX event handlers // UX event handlers
$rootScope.$on('Local/ColorUpdated', function(event) { $rootScope.$on('Local/ColorUpdated', function(event) {
self.updateColor(); self.updateColor();
@ -913,8 +948,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}); });
$rootScope.$on('Local/GlideraTokenUpdated', function() { $rootScope.$on('Local/GlideraTokenUpdated', function(event, accessToken) {
self.initGlidera(); self.initGlidera(accessToken);
});
$rootScope.$on('Local/GlideraUpdated', function(event, accessToken, permissions) {
self.updateGlidera(accessToken, permissions);
}); });
$rootScope.$on('Local/UnitSettingUpdated', function(event) { $rootScope.$on('Local/UnitSettingUpdated', function(event) {

View file

@ -1,11 +1,11 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesGlideraController', angular.module('copayApp.controllers').controller('preferencesGlideraController',
function($scope, $timeout, profileService, go, glideraService, storageService) { function($scope, $timeout, profileService, applicationService, glideraService, storageService) {
this.init = function(token) { this.init = function(token) {
var self = this; var self = this;
glideraService.getPermissions(token, function(error, permission) { glideraService.getAccessTokenPermissions(token, function(error, permission) {
self.permission = permission; self.permission = permission;
}); });
@ -29,9 +29,8 @@ angular.module('copayApp.controllers').controller('preferencesGlideraController'
this.revokeToken = function() { this.revokeToken = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
storageService.removeGlideraToken(fc.credentials.network, function() { storageService.removeGlideraToken(fc.credentials.network, function() {
$scope.$emit('Local/GlideraTokenUpdated');
$timeout(function() { $timeout(function() {
go.walletHome(); applicationService.restart();
}, 100); }, 100);
}); });
}; };

View file

@ -53,7 +53,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
}; };
}; };
root.getPermissions = function(token, cb) { root.getAccessTokenPermissions = function(token, cb) {
if (!token) return cb('Invalid Token'); if (!token) return cb('Invalid Token');
$http(_get('/oauth/token', token)).then(function(data) { $http(_get('/oauth/token', token)).then(function(data) {
$log.info('Glidera Access Token Permissions: SUCCESS'); $log.info('Glidera Access Token Permissions: SUCCESS');