Skip to content

Commit

Permalink
tested on listen page
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Nov 30, 2014
1 parent 8069254 commit c24d957
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ var app = angular.module('baw',
// cross-site scripting token storage
$rootScope.csrfToken = null;

// storage of auth_token
$rootScope.authorisationToken = null;

// storage of auth_token - now done in authenticator
/* deprecated */
$rootScope.authTokenParams = function () {
if ($rootScope.authorisationToken) {
return {
Expand All @@ -327,14 +326,15 @@ var app = angular.module('baw',
return $url.toKeyValue($rootScope.authTokenParams());
};


$rootScope.loggedIn = false;

$rootScope.$watch('userData', function () {
var token = $rootScope.authorisationToken,
userData = $rootScope.userData;
$rootScope.loggedIn = (token && userData) ? true : false;

});
}); /* /deprecated */

$rootScope.downloadAnnotationLink = AudioEvent.csvLink();

Expand Down
6 changes: 3 additions & 3 deletions src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
}
});

/* // NOT NECESSARY - we aren't using auth keys atm */
$scope.$on('event:auth-loginRequired', function(){ $scope.model.media.formatPaths(); });
$scope.$on('event:auth-loginConfirmed', function(){ $scope.model.media.formatPaths(); });
// update urls on login events
$scope.$on('event:auth-loginRequired', function(){ if($scope.model.media) {$scope.model.media.formatPaths();} });
$scope.$on('event:auth-loginConfirmed', function(){ if($scope.model.media) {$scope.model.media.formatPaths();} });

var media = MediaService
.get(
Expand Down
58 changes: 31 additions & 27 deletions src/components/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,33 @@
// authentication...
bawss.factory('Authenticator', ['$rootScope', 'authService', '$http', 'conf.paths',
function ($rootScope, authService, $http, paths) {
// As soon as the module is initiated...
// WARNING: Cookies required for this to work
checkLogin();

var that = {
loginSuccess: loginSuccess,
loginFailure: loginFailure,
logoutSuccess: function logoutSuccess(data, status, headers, config) {
$rootScope.$safeApply($rootScope, function () {
that.authToken = null;
$rootScope.userData = null;
$http.defaults.headers.common["Authorization"] = null;

console.log("Logout successful", data);
});
},
logoutFailure: function logoutFailure(data, status, headers, config) {
console.error("Logout failure: ", data, status, headers, config);
},
checkLogin: checkLogin,
authToken: null
};

return that;

// functions

function loginSuccess(data, status, headers, config) {
// a provider has just logged in
// the response arg, is the response from our server (devise)
Expand All @@ -421,13 +448,13 @@
throw "Authenticator.loginSuccess: this function should not be called unless a successful response was received";
}

if (data.authorisationToken === undefined) {
if (data.authToken === undefined) {
throw "The authorisation token can not be undefined at this point";
}

this.authorisationToken = data.authToken;
that.authToken = data.authToken;
$http.defaults.headers.common["Authorization"] = 'Token token="' +
$rootScope.authorisationToken +
that.authToken +
'"';

$rootScope.$safeApply($rootScope, function () {
Expand All @@ -439,7 +466,7 @@

function loginFailure(data, status, headers, config) {
$rootScope.$safeApply($rootScope, function () {
$rootScope.authorisationToken = null;
that.authToken = null;
$rootScope.userData = null;
$http.defaults.headers.common["Authorization"] = null;

Expand Down Expand Up @@ -490,29 +517,6 @@

return true;
}

// As soon as the module is initiated...
// WARNING: Cookies required for this to work
checkLogin();

return {
loginSuccess: loginSuccess,
loginFailure: loginFailure,
logoutSuccess: function logoutSuccess(data, status, headers, config) {
$rootScope.$safeApply($rootScope, function () {
$rootScope.authorisationToken = null;
$rootScope.userData = null;
$http.defaults.headers.common["Authorization"] = null;

console.log("Logout successful", data);
});
},
logoutFailure: function logoutFailure(data, status, headers, config) {
console.error("Logout failure: ", data, status, headers, config);
},
checkLogin: checkLogin,
authToken: null
};
}]);

bawss.factory('AuthenticationProviders',
Expand Down

0 comments on commit c24d957

Please sign in to comment.