Refresh the token

This commit is contained in:
Philippe Vienne 2016-04-17 21:19:01 +02:00
parent 148a2f6df4
commit 156f06bc20
2 changed files with 13 additions and 9 deletions

View file

@ -28,10 +28,10 @@
</ul>
<ul class="nav navbar-nav navbar-right" ng-controller="AuthCtrl">
<li ng-if="access_token == ''">
<a href="#" ng-click="login()" class="dropdown-toggle" data-toggle="dropdown"><b>Login With Spotify</b></a>
<a ng-click="login()" href="#"><b>Login With Spotify</b></a>
</li>
<li ng-if="access_token != ''">
<a href="#" ng-click="refresh()" class="dropdown-toggle" data-toggle="dropdown"><b>Refresh my token</b></a>
<a ng-click="refresh()" href="#"><b>Refresh my token</b></a>
</li>
</ul>
</div><!-- /.navbar-collapse -->

View file

@ -58,7 +58,7 @@
}]);
app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', function($scope, $rootScope, $interval){
app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', '$http', function($scope, $rootScope, $interval, $http){
$scope.login = function(){
var openUrl = '/login';
window.$windowScope = $scope;
@ -71,16 +71,20 @@
$rootScope.refresh_token = $scope.popup.token.refresh_token;
$scope.popup.close();
$interval.cancel(checker);
} else if ($scope.popup.token == null){
$scope.popup.close();
$interval.cancel(checker);
}
}, 500);
return false;
};
$scope.refresh = function(){
var openUrl = '/refresh_token';
window.$windowScope = $scope;
window.open(openUrl, "Authenticate Account", "width=500, height=500");
if($rootScope.refresh_token)
$http.get('/refresh_token',{params: {refresh_token: $rootScope.refresh_token}})
.then(function(result){
$rootScope.access_token = result.data.access_token || "";
}, function(failResult){
$rootScope.access_token = "";
$rootScope.refresh_token = "";
});
return false;
}
}])