Fix glidera getting token

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-08 10:17:59 -03:00
parent c6a5c77516
commit f574a9d78b
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
5 changed files with 53 additions and 42 deletions

View File

@ -17,13 +17,30 @@
<div class="rect4"></div>
<div class="rect5"></div>
</div>
<span ng-show="glidera.loading" translate>Linking to Glidera...</span>
<span ng-show="glidera.loading" translate>Connecting to Glidera...</span>
<span ng-show="index.glideraLoading">{{index.glideraLoading|translate}}</span>
</div>
</div>
<div class="text-center m10b">
<img src="img/glidera-logo.png">
<div class="row">
<div class="columns">
<div class="text-center m20b">
<img src="img/glidera-logo.png">
</div>
<div class="m20b box-notification" ng-if="index.glideraError || glidera.error">
<div class="text-warning">
<span ng-show="index.glideraError == 'Unauthorized'" translate>Could not connect to Glidera: Unauthorized</span>
<span ng-show="index.glideraError == 'Forbidden'" translate>Could not connect to Glidera: Forbidden</span>
<span ng-show="index.glideraError != ('Forbidden' && 'Unauthorized')">{{index.glideraError || glidera.error}}</span>
</div>
<div class="m10t" ng-show="index.glideraToken && index.glideraError == 'Forbidden'">
<button class="round tiny" ng-click="index.glideraToken = null; index.glideraError = null">
Request a new token
</button>
</div>
</div>
</div>
</div>
<div ng-if="index.glideraCredentials && !index.glideraToken && !index.glideraLoading && !index.glideraError"
@ -44,34 +61,22 @@
</div>
</div>
<div class="text-center" ng-show="showOauthForm">
<p class="text-gray size-12">Paste the authorization code here</p>
<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 type="text" ng-model="code" ng-disabled="glidera.loading"
ng-attr-placeholder="{{'Paste the authorization code here'|translate}}" required>
<input
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>
<a href class="size-12 text-gray"
ng-click="showOauthForm = false; index.glideraError = null; glidera.error = null" translate>Go back</a>
</div>
</div>
</div>
</div>
<div class="m20t text-center" ng-if="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')">{{index.glideraError}}</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>
<div ng-if="index.glideraToken && index.glideraPermissions"
ng-init="glidera.update(index.glideraToken, index.glideraPermissions)">

View File

@ -65,7 +65,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
glideraService.buy(token, twoFaCode, data, function(err, data) {
self.loading = null;
if (err) {
self.error = gettext('Could not buy bitcoin');
self.error = err;
}
else {
self.success = data;

View File

@ -9,17 +9,23 @@ angular.module('copayApp.controllers').controller('glideraController',
return glideraService.getOauthCodeUrl();
};
this.submitOauthCode = function(code, glideraCredentials) {
this.submitOauthCode = function(code) {
var fc = profileService.focusedClient;
var self = this;
this.loading = true;
$timeout(function() {
glideraService.getToken(code, glideraCredentials, function(error, data) {
if (data && data.access_token) {
glideraService.getToken(code, function(err, data) {
self.loading = null;
if (err) {
self.error = err;
$timeout(function() {
$scope.$apply();
}, 100);
}
else if (data && data.access_token) {
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
$scope.$emit('Local/GlideraTokenUpdated', data.access_token);
$timeout(function() {
self.loading = null;
$scope.$apply();
}, 100);
});

View File

@ -112,7 +112,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
glideraService.sell(token, twoFaCode, data, function(err, data) {
self.loading = null;
if (err) {
self.error = gettext('Could not sell bitcoin');
self.error = err;
fc.removeTxProposal(txp, function(err, txpb) {
$timeout(function() {
$scope.$emit('Local/GlideraError');

View File

@ -50,7 +50,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Authorization Access Token: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Authorization Access Token: ERROR ' + data.statusText);
});
};
@ -73,7 +73,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Access Token Permissions: ERROR ' + data.statusText);
return cb('Glidera Access Token Permissions: ERROR');
return cb('Glidera Access Token Permissions: ERROR ' + data.statusText);
});
};
@ -84,7 +84,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Get Email: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Get Email: ERROR ' + data.statusText);
});
};
@ -95,7 +95,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Get Personal Info: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Get Personal Info: ERROR ' + data.statusText);
});
};
@ -106,7 +106,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera User Status: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera User Status: ERROR ' + data.statusText);
});
};
@ -117,7 +117,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Transaction Limits: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Transaction Limits: ERROR ' + data.statusText);
});
};
@ -128,7 +128,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data.transactions);
}, function(data) {
$log.error('Glidera Transactions: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Transactions: ERROR ' + data.statusText);
});
};
@ -140,7 +140,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Transaction: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Transaction: ERROR ' + data.statusText);
});
};
@ -151,7 +151,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data.sellAddress);
}, function(data) {
$log.error('Glidera Create Sell Address: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Create Sell Address: ERROR ' + data.statusText);
});
};
@ -162,7 +162,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.status == 200 ? true : false);
}, function(data) {
$log.error('Glidera Sent 2FA code by SMS: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Sent 2FA code by SMS: ERROR ' + data.statusText);
});
};
@ -190,7 +190,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Sell Price: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Sell Price: ERROR ' + data.statusText);
});
};
@ -206,8 +206,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
$log.info('Glidera Sell: SUCCESS');
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Sell: ERROR ' + data.statusText);
return cb(data.statusText);
$log.error('Glidera Sell Request: ERROR ' + data.statusText);
return cb('Glidera Sell Request: ERROR ' + data.statusText);
});
};
@ -221,7 +221,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Buy Price: ERROR ' + data.statusText);
return cb(data.statusText);
return cb('Glidera Buy Price: ERROR ' + data.statusText);
});
};
@ -237,8 +237,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
$log.info('Glidera Buy: SUCCESS');
return cb(null, data.data);
}, function(data) {
$log.error('Glidera Buy: ERROR ' + data.statusText);
return cb(data.statusText);
$log.error('Glidera Buy Request: ERROR ' + data.statusText);
return cb('Glidera Buy Request: ERROR ' + data.statusText);
});
};