Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

[WIP] Use oauth module from PJC #128

Merged
merged 3 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions app/modules/auth/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
var auth = localStorageService.get('auth');
if (0 < (Math.floor(Date.now() / 1000) - auth.token_start) < auth.expires_in) {
_setToken(auth.access_token);
_startTimer();
_setUserData();
} else {
signOut();
Expand All @@ -55,7 +54,6 @@
expires_in: params.expires_in * 1000
});
_setToken(params.access_token);
_startTimer();
return _setUserData()
.then(function () {
$window.location.href = localStorageService.get('redirectOnSignIn');
Expand All @@ -64,13 +62,7 @@

function signIn() {
localStorageService.set('redirectOnSignIn', $location.absUrl());
$window.location.href = zooAPI.root.match(/^(.*)\/[^/]*$/)[1] +
'/oauth/authorize' +
'?response_type=token' +
'&client_id=' +
zooAPIConfig.app_id +
'&redirect_uri=' +
$location.absUrl().match(/.+?(?=\#\/)/)[0];
$window.zooOAuth.signIn($location.absUrl().match(/.+?(?=\#\/)/)[0]);
}

function _setToken(token) {
Expand Down Expand Up @@ -108,18 +100,6 @@
$rootScope.$broadcast('auth:signout');
}

function _startTimer() {
var auth = localStorageService.get('auth');
var expiry = auth.token_start + auth.expires_in - Date.now();
$interval(function () {
signOut();
$modal.open({
templateUrl: 'templates/auth/session-expired.html',
controller: 'SessionExpiredModalController'
});
}, expiry, 1);
}

return {
signIn: signIn,
signOut: signOut,
Expand Down
63 changes: 4 additions & 59 deletions app/modules/zoo-api/scripts/project-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

module.factory('zooAPI', function ($window, zooAPIConfig) {
console.log('zooAPIConfig = ', zooAPIConfig);
$window.zooAPI.root = zooAPIConfig.url;
$window.zooAPI.appID = zooAPIConfig.app_id;
$window.zooOAuth.init(zooAPIConfig.app_id);
return $window.zooAPI;
});

Expand All @@ -56,16 +55,10 @@
var get = function () {
var deferred = $q.defer();

var cache = localStorageService.get('project');
if (cache) {
deferred.resolve(cache);
}

zooAPI.type('projects').get({display_name: zooAPIConfig.display_name})
.then(function (response) {
var data = $filter('removeCircularDeps')(response[0]);
localStorageService.set('project', data);
deferred.resolve(localStorageService.get('project'));
deferred.resolve(data);
});

return deferred.promise;
Expand All @@ -80,26 +73,9 @@
var get = function (filter) {
var deferred = $q.defer();

var cache = localStorageService.get('workflows');
if (cache) {
if (filter) {
var cacheByID = _.find(cache, filter);
if (angular.isDefined(cacheByID)) {
deferred.notify([cacheByID]);
}
} else {
deferred.notify(cache);
}
} else {
cache = [];
}

zooAPI.type('workflows').get(filter)
.then(function (response) {
upsert(cache, {id: response.id}, response);
cache = $filter('removeCircularDeps')(cache);
localStorageService.set('workflows', cache);
deferred.resolve(response);
deferred.resolve($filter('removeCircularDeps')(response));
});

return deferred.promise;
Expand All @@ -114,20 +90,6 @@
var get = function (filter) {
var deferred = $q.defer();

var cache = localStorageService.get('subject_sets');
if (cache) {
if (filter) {
var cacheByID = _.find(cache, filter);
if (angular.isDefined(cacheByID)) {
deferred.notify([cacheByID]);
}
} else {
deferred.notify(cache);
}
} else {
cache = [];
}

zooAPIProject.get()
.then(function (response) {
var options = {
Expand Down Expand Up @@ -160,24 +122,7 @@
deferred.notify(subjectSets);
loadPages(angular.extend({}, options, {page: meta.next_page}));
} else {
angular.forEach(subjectSets, function (s) {
upsert(cache, {'id': s.id}, s);
});

// If an item in the cache, is not in the list returned by the server
// and we're not filtering (assuming we're loading all data here!)
if (!filter) {
angular.forEach(cache, function (c) {
if (angular.isUndefined(_.find(subjectSets, {id: c.id}))) {
_.remove(cache, c);
}
});
}

cache = $filter('removeCircularDeps')(cache);
localStorageService.set('subject_sets', cache);

deferred.resolve(subjectSets);
deferred.resolve($filter('removeCircularDeps')(subjectSets));
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"karma-firefox-launcher": "^0.1.6",
"karma-jasmine": "0.3.5",
"nib": "1.1.0",
"panoptes-client": "^2.5.1",
"panoptes-client": "^2.5.2",
"run-sequence": "^1.1.0",
"stylus": "^0.51.1"
},
Expand Down
3 changes: 2 additions & 1 deletion panoptes-client-wrapper/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
window.zooAPI = require('panoptes-client/lib/api-client');
window.zooAuth = require('panoptes-client/lib/auth');
window.zooAuth = require('panoptes-client/lib/auth');
window.zooOAuth = require('panoptes-client/lib/oauth');