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 class="text-center m10b">
<img src="img/glidera-logo.png" ng-click="glidera.update(index.glideraToken)">
<img src="img/glidera-logo.png">
</div>
<div ng-if="!index.glideraToken" class="row">
<div class="columns" ng-init="showOauthForm = false">
<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 class="text-gray size-12">Connect your Glidera account to get started</p>
<p translate>You can buy and sell Bitcoin with a US bank account directly in Copay.</p>
<div class="m10b text-gray size-12" translate>Connect your Glidera account to get started</div>
<button
class="dark-gray outline round tiny"
ng-click="$root.openExternalLink(glidera.authenticateUrl); showOauthForm = true" translate>
Connect to Glidera
</button>
<a href ng-click="showOauthForm = true" class="db text-gray size-12">
Do you already have the Oauth Code?
</a>
<div>
<a href ng-click="showOauthForm = true" class="text-gray size-12">
Do you already have the Oauth Code?
</a>
</div>
</div>
<div class="text-center" ng-show="showOauthForm">
<p class="text-gray size-12">Paste the authorization code here</p>
<form name="oauthCode" ng-submit="glidera.submitOauthCode(code)" novalidate>
<label>OAuth Code<label>
<input type="text" ng-model="code" ng-disabled="glidera.loading">
<form name="oauthCodeForm" ng-submit="glidera.submitOauthCode(code)" novalidate>
<label>OAuth Code</label>
<input type="text" ng-model="code" ng-disabled="glidera.loading" required>
<input
class="button dark-gray outline round"
type="submit" value="Get started" ng-disabled="glidera.loading">
class="button expand round"
ng-style="{'background-color':index.backgroundColor}"
type="submit" value="Get started" ng-disabled="oauthCodeForm.$invalid || glidera.loading">
</form>
<div>
<a href class="size-12 text-gray" ng-click="showOauthForm = false" translate>Go back</a>
</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">
{{index.glideraEmail}} <br>
<a href class="text-gray" ng-click="$root.go('preferencesGlidera')">
Preferences
</a>
</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')">
<span translate>Buy</span>
<span class="right text-gray">
@ -74,33 +102,39 @@
</li>
</ul>
<h4 class="title m0" translate>Activity</h4>
<div ng-repeat="tx in index.glideraTxs"
ng-click="glidera.openTxModal(index.glideraToken, tx)"
class="row collapse last-transactions-content">
<div class="large-3 medium-3 small-3 columns">
<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 ng-show="index.glideraPermissions.transaction_history">
<h4 class="title m0" translate>Activity</h4>
<div ng-show="!index.glideraTxs"
class="size-12 p10 text-center text-gray" translate>
No activity in your account
</div>
<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 ng-repeat="tx in index.glideraTxs"
ng-click="glidera.openTxModal(index.glideraToken, tx)"
class="row collapse last-transactions-content">
<div class="large-3 medium-3 small-3 columns">
<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 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 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>

View file

@ -1,21 +1,11 @@
'use strict';
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;
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) {
var fc = profileService.focusedClient;
var self = this;
@ -24,9 +14,9 @@ angular.module('copayApp.controllers').controller('glideraController',
glideraService.getToken(code, function(error, data) {
if (data && data.access_token) {
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
$scope.$emit('Local/GlideraTokenUpdated');
$scope.$emit('Local/GlideraTokenUpdated', data.access_token);
$timeout(function() {
self.loading = false;
self.loading = null;
$scope.$apply();
}, 100);
});

View file

@ -114,8 +114,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setSpendUnconfirmed();
self.glideraToken = null;
self.glideraTxs = null;
self.glideraPermissions = null;
self.glideraEmail = null;
self.glideraPersonalInfo = null;
self.glideraTxs = null;
$timeout(function() {
self.hasProfile = true;
@ -848,22 +850,55 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}), 'name');
};
self.initGlidera = function() {
self.initGlidera = function(accessToken) {
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 {
self.glideraToken = val;
glideraService.getTransactions(val, function(error, txs) {
self.glideraTxs = txs;
});
glideraService.getEmail(val, function(error, data) {
self.glideraEmail = data.email;
self.glideraToken = accessToken;
glideraService.getAccessTokenPermissions(self.glideraToken, function(err, p) {
if (err) {
self.glideraError = err;
$log.error(err);
}
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
$rootScope.$on('Local/ColorUpdated', function(event) {
self.updateColor();
@ -913,8 +948,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
});
$rootScope.$on('Local/GlideraTokenUpdated', function() {
self.initGlidera();
$rootScope.$on('Local/GlideraTokenUpdated', function(event, accessToken) {
self.initGlidera(accessToken);
});
$rootScope.$on('Local/GlideraUpdated', function(event, accessToken, permissions) {
self.updateGlidera(accessToken, permissions);
});
$rootScope.$on('Local/UnitSettingUpdated', function(event) {

View file

@ -1,11 +1,11 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesGlideraController',
function($scope, $timeout, profileService, go, glideraService, storageService) {
function($scope, $timeout, profileService, applicationService, glideraService, storageService) {
this.init = function(token) {
var self = this;
glideraService.getPermissions(token, function(error, permission) {
glideraService.getAccessTokenPermissions(token, function(error, permission) {
self.permission = permission;
});
@ -29,9 +29,8 @@ angular.module('copayApp.controllers').controller('preferencesGlideraController'
this.revokeToken = function() {
var fc = profileService.focusedClient;
storageService.removeGlideraToken(fc.credentials.network, function() {
$scope.$emit('Local/GlideraTokenUpdated');
$timeout(function() {
go.walletHome();
applicationService.restart();
}, 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');
$http(_get('/oauth/token', token)).then(function(data) {
$log.info('Glidera Access Token Permissions: SUCCESS');