Refresh the token
This commit is contained in:
parent
148a2f6df4
commit
156f06bc20
2 changed files with 13 additions and 9 deletions
|
@ -28,10 +28,10 @@
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right" ng-controller="AuthCtrl">
|
<ul class="nav navbar-nav navbar-right" ng-controller="AuthCtrl">
|
||||||
<li ng-if="access_token == ''">
|
<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>
|
||||||
<li ng-if="access_token != ''">
|
<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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div><!-- /.navbar-collapse -->
|
</div><!-- /.navbar-collapse -->
|
||||||
|
|
|
@ -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(){
|
$scope.login = function(){
|
||||||
var openUrl = '/login';
|
var openUrl = '/login';
|
||||||
window.$windowScope = $scope;
|
window.$windowScope = $scope;
|
||||||
|
@ -71,16 +71,20 @@
|
||||||
$rootScope.refresh_token = $scope.popup.token.refresh_token;
|
$rootScope.refresh_token = $scope.popup.token.refresh_token;
|
||||||
$scope.popup.close();
|
$scope.popup.close();
|
||||||
$interval.cancel(checker);
|
$interval.cancel(checker);
|
||||||
} else if ($scope.popup.token == null){
|
|
||||||
$scope.popup.close();
|
|
||||||
$interval.cancel(checker);
|
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
$scope.refresh = function(){
|
$scope.refresh = function(){
|
||||||
var openUrl = '/refresh_token';
|
if($rootScope.refresh_token)
|
||||||
window.$windowScope = $scope;
|
$http.get('/refresh_token',{params: {refresh_token: $rootScope.refresh_token}})
|
||||||
window.open(openUrl, "Authenticate Account", "width=500, height=500");
|
.then(function(result){
|
||||||
|
$rootScope.access_token = result.data.access_token || "";
|
||||||
|
}, function(failResult){
|
||||||
|
$rootScope.access_token = "";
|
||||||
|
$rootScope.refresh_token = "";
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue