Popup Login

This commit is contained in:
Philippe Vienne 2016-04-17 20:54:06 +02:00
parent fc7848a43e
commit 148a2f6df4
2 changed files with 17 additions and 11 deletions

11
app.js
View file

@ -91,16 +91,9 @@ app.get('/callback', function (req, res) {
refresh_token = body.refresh_token;
// we can also pass the token to the browser to make requests from there
res.redirect('/#' +
querystring.stringify({
access_token: access_token,
refresh_token: refresh_token
}));
res.send('<script>window.token = { access_token: "'+access_token+'", refresh_token: "'+refresh_token+'" };</script>')
} else {
res.redirect('/#' +
querystring.stringify({
error: 'invalid_token'
}));
res.send('<script>window.token = { access_token: "", refresh_token: "" };</script>')
}
});
}

View file

@ -58,11 +58,24 @@
}]);
app.controller('AuthCtrl',['$scope', '$rootScope', function($scope, $rootScope){
app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', function($scope, $rootScope, $interval){
$scope.login = function(){
var openUrl = '/login';
window.$windowScope = $scope;
window.open(openUrl, "Authenticate Account", "width=500, height=500");
$scope.popup = window.open(openUrl, "Authenticate Account", "width=500, height=500");
var checker = $interval(function(){
if($scope.popup.closed){
$interval.cancel(checker);
} else if ($scope.popup.token != undefined && $scope.popup.token != null) {
$rootScope.access_token = $scope.popup.token.access_token;
$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);
};
$scope.refresh = function(){
var openUrl = '/refresh_token';