Last active
January 9, 2017 18:55
-
-
Save bwalsh/a23fb3a2d45e4094ca648f8fab2e4837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dcc-portal-ui/app/scripts/auth/js/auth.js b/dcc-portal-ui/app/scripts/auth/js/auth.js | |
index d5f6d81..5663a8e 100644 | |
--- a/dcc-portal-ui/app/scripts/auth/js/auth.js | |
+++ b/dcc-portal-ui/app/scripts/auth/js/auth.js | |
@@ -47,7 +47,6 @@ | |
user.verifying = false; | |
console.log('ohsutoken present'); | |
user.token = ohsutoken; | |
- return ; | |
} | |
handler.one('verify').get().then(succ, function(){ | |
user.verifying = false; | |
@@ -121,7 +120,7 @@ | |
function login(osDomain, osUsername, osPassword) { | |
var credentials = {'domain': osDomain, 'user': osUsername, 'password': osPassword}; | |
- | |
+ $window.localStorage.setItem('ohsu-refresh-needed', 'true'); | |
return handler.withHttpConfig({ | |
transformRequest: function(data) { | |
return JSON.stringify(data); | |
@@ -146,11 +145,21 @@ | |
return !!$cookies.ohsulogin_error; | |
} | |
+ function refreshNeeded() { | |
+ return $window.localStorage.getItem('ohsu-refresh-needed'); | |
+ } | |
+ | |
+ function refreshDone() { | |
+ return $window.localStorage.removeItem('ohsu-refresh-needed'); | |
+ } | |
+ | |
return { | |
login: login, | |
logout: logout, | |
getErrors: getErrors, | |
- hasErrors: hasErrors | |
+ hasErrors: hasErrors, | |
+ refreshNeeded: refreshNeeded, | |
+ refreshDone: refreshDone | |
}; | |
}); | |
@@ -218,6 +227,10 @@ | |
break; | |
} | |
+ if ($scope.params.provider === 'ohsu') { | |
+ shouldRefresh = true; | |
+ } | |
+ | |
return shouldRefresh; | |
} | |
@@ -253,6 +266,10 @@ | |
// If we are on the homepage (i.e. $state.current.name is falsey) don't bother transitioning... | |
if ($state.current.name) { | |
$state.transitionTo($state.current, $stateParams, transitionParams); | |
+ if (OHSU.refreshNeeded()) { | |
+ OHSU.refreshDone(); | |
+ $window.location.reload(); | |
+ } | |
} | |
$scope.closeLoginPopup(); | |
diff --git a/dcc-portal-ui/app/scripts/app/js/app.js b/dcc-portal-ui/app/scripts/app/js/app.js | |
index 2a97fc6..76847d0 100644 | |
--- a/dcc-portal-ui/app/scripts/app/js/app.js | |
+++ b/dcc-portal-ui/app/scripts/app/js/app.js | |
@@ -471,12 +471,12 @@ | |
}) | |
.run(function($state, $location, $window, $timeout, $rootScope, cfpLoadingBar, HistoryManager, gettextCatalog, Settings) { | |
- | |
+ | |
// Setting the initial language to English CA. | |
gettextCatalog.setCurrentLanguage('en_CA'); | |
HistoryManager.addToIgnoreScrollResetWhiteList(['analysis','advanced', 'compound', 'dataRepositories', 'donor', 'beacon', 'project', 'gene']); | |
- | |
+ | |
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
if(error.status === 404){ | |
$state.go('404', {page: toState.name, id: toParams.id, url: toState.url}, {location: false}); | |
@@ -567,6 +567,13 @@ | |
} | |
}); | |
+ RestangularProvider.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) { | |
+ var ohsutoken = window.localStorage.getItem('ohsutoken') ; | |
+ if (ohsutoken) { | |
+ return {headers: {'Authorization': 'Bearer ' + ohsutoken}}; | |
+ } | |
+ }); | |
+ | |
RestangularProvider.setDefaultHttpFields({cache: true}); | |
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; | |
diff --git a/dcc-portal-ui/app/scripts/auth/js/auth.js b/dcc-portal-ui/app/scripts/auth/js/auth.js | |
index 5a4a53e..d5f6d81 100644 | |
--- a/dcc-portal-ui/app/scripts/auth/js/auth.js | |
+++ b/dcc-portal-ui/app/scripts/auth/js/auth.js | |
@@ -42,6 +42,13 @@ | |
user.verifying = false; | |
return; | |
} | |
+ var ohsutoken = $window.localStorage.getItem('ohsutoken'); | |
+ if (ohsutoken) { | |
+ user.verifying = false; | |
+ console.log('ohsutoken present'); | |
+ user.token = ohsutoken; | |
+ return ; | |
+ } | |
handler.one('verify').get().then(succ, function(){ | |
user.verifying = false; | |
}); | |
@@ -63,6 +70,7 @@ | |
delete $cookies.dcc_session; | |
delete $cookies.dcc_user; | |
Restangular.setDefaultRequestParams({}); | |
+ $window.localStorage.removeItem('ohsutoken'); | |
$window.location.reload(); | |
} | |
@@ -108,6 +116,45 @@ | |
}; | |
}); | |
+ angular.module('icgc.auth.models').factory('OHSU', function (Restangular, $window, $cookies, Auth) { | |
+ var handler = Restangular.one('ohsulogin'); | |
+ | |
+ function login(osDomain, osUsername, osPassword) { | |
+ var credentials = {'domain': osDomain, 'user': osUsername, 'password': osPassword}; | |
+ | |
+ return handler.withHttpConfig({ | |
+ transformRequest: function(data) { | |
+ return JSON.stringify(data); | |
+ } | |
+ }).customPOST(credentials, undefined, undefined, { | |
+ 'Content-Type': 'application/json' | |
+ }); | |
+ | |
+ } | |
+ | |
+ function logout() { | |
+ $cookies.ohsulogin_error = undefined; | |
+ $window.localStorage.removeItem('ohsutoken'); | |
+ } | |
+ | |
+ | |
+ function getErrors() { | |
+ return $cookies.ohsulogin_error; | |
+ } | |
+ | |
+ function hasErrors() { | |
+ return !!$cookies.ohsulogin_error; | |
+ } | |
+ | |
+ return { | |
+ login: login, | |
+ logout: logout, | |
+ getErrors: getErrors, | |
+ hasErrors: hasErrors | |
+ }; | |
+ }); | |
+ | |
+ | |
angular.module('icgc.auth.models').factory('OpenID', function (Restangular, $window, $cookies) { | |
var handler = Restangular.one('auth/openid'); | |
@@ -136,20 +183,24 @@ | |
}); | |
})(); | |
+ | |
(function () { | |
'use strict'; | |
angular.module('icgc.auth.controllers', ['icgc.auth.models']); | |
angular.module('icgc.auth.controllers').controller('authController', | |
- function ($window, $scope, $location, $modal, Auth, CUD, OpenID, $state, $stateParams, | |
- PortalFeature, gettextCatalog) { | |
+ function ($window, $scope, $location, $modal, Auth, CUD, OpenID, $state, $stateParams, | |
+ PortalFeature, gettextCatalog, OHSU) { | |
$scope.params = {}; | |
- $scope.params.provider = 'google'; | |
+ $scope.params.provider = 'ohsu'; | |
$scope.params.error = null; | |
$scope.params.user = null; | |
$scope.params.openIDUrl = null; | |
+ $scope.params.osDomain = null; | |
+ $scope.params.osUsername = null; | |
+ $scope.params.osPassword = null; | |
$scope.params.cudUsername = null; | |
$scope.params.cudPassword = null; | |
$scope.params.showCollaboratoryToken = PortalFeature.get('AUTH_TOKEN'); | |
@@ -159,7 +210,7 @@ | |
urlPath = $location.path().toLowerCase(); | |
switch(urlPath) { | |
- // Currently, we only want a refresh for releases. | |
+ // Currently, we only want a refresh for releases. | |
case '/releases': | |
shouldRefresh = true; | |
break; | |
@@ -176,8 +227,10 @@ | |
if (OpenID.hasErrors()) { | |
$scope.params.error = OpenID.getErrors(); | |
$scope.loginModal = true; | |
- } | |
- else { | |
+ } else if (OHSU.hasErrors()) { | |
+ $scope.params.error = OHSU.getErrors(); | |
+ $scope.loginModal = true; | |
+ } else { | |
Auth.checkSession( | |
function (data) { | |
@@ -282,7 +335,25 @@ | |
$scope.tryLogin = function () { | |
$scope.connecting = true; | |
- if ( ['icgc', 'google'].indexOf($scope.params.provider) >= 0) { | |
+ if ( ['ohsu'].indexOf($scope.params.provider) >= 0) { | |
+ console.log('call ohsu login...'); | |
+ OHSU.login($scope.params.osDomain, $scope.params.osUsername, $scope.params.osPassword) | |
+ .then(function(response) { | |
+ console.log('handle ohsulogin ok', response); | |
+ $window.localStorage.setItem('ohsutoken',response.id_token); | |
+ Auth.login({token: response.id_token, | |
+ username: $scope.params.osUsername}); | |
+ $scope.connecting = false; | |
+ $scope.params.error = undefined; | |
+ setup(); | |
+ $scope.closeLoginPopup(); | |
+ }, function(response) { | |
+ console.log('handle ohsulogin error', response); | |
+ $window.localStorage.removeItem('ohsutoken'); | |
+ $scope.connecting = false; | |
+ $scope.params.error = response.data + '(' + response.status + ')'; | |
+ }); | |
+ } else if ( ['icgc', 'google'].indexOf($scope.params.provider) >= 0) { | |
CUD.login( $scope.params.provider ); | |
} else { | |
OpenID.provider(providerMap($scope.params.provider)).then( | |
diff --git a/dcc-portal-ui/app/scripts/auth/views/login.popup.html b/dcc-portal-ui/app/scripts/auth/views/login.popup.html | |
index eb5f098..2777a99 100644 | |
--- a/dcc-portal-ui/app/scripts/auth/views/login.popup.html | |
+++ b/dcc-portal-ui/app/scripts/auth/views/login.popup.html | |
@@ -7,39 +7,47 @@ | |
</div> | |
<div class="modal-body" style="max-height:none;padding-bottom:0"> | |
- <div data-ng-hide="error" class="alert-info"> | |
+ <div data-ng-hide="params.error" class="alert-info"> | |
<translate>Sign in using your ICGC DACO-approved account for controlled data</translate> | |
</div> | |
- <div data-ng-show="error"> | |
+ <div data-ng-show="params.error"> | |
<div class="alert-error"> | |
{{params.error}} | |
</div> | |
<div class="alert"> | |
- <translate>Problems logging in?</translate> | |
+ <translate>Problems logging in?</translate> | |
<a href="mailto:[email protected]?Subject=Problem%20Logging%20In"><i | |
class="icon-mail"></i> <translate>Contact Us</translate></a> <translate>or</translate> | |
<a href="http://icgc.org/daco/"><i class="icon-pilcrow"></i> <translate>Apply for access to controlled data.</translate></a> | |
</div> | |
</div> | |
<ul class="open-id-providers"> | |
- <li class="open-id-provider" data-ng-class="{active: params.provider=='icgc'}" | |
- data-ng-click="params.provider='icgc'"><span class="logo"><img | |
+ <li class="open-id-provider" data-ng-class="{active: params.provider=='ohsu'}" | |
+ data-ng-click="params.provider='ohsu'"> | |
+ <span class="logo"> | |
+ <img src="/styles/images/ohsu-logo.png"></span> | |
+ </li> | |
+ | |
+ <li class="open-id-provider" data-ng-class="{active: params.provider=='icgc'}"> | |
+ <span class="logo"><img | |
src="/styles/images/icgc_open_id.png"></span></li> | |
- <li class="open-id-provider" data-ng-class="{active: params.provider=='google'}" | |
- data-ng-click="params.provider='google'"><span class="logo"><img | |
+ <li class="open-id-provider" data-ng-class="{active: params.provider=='google'}"> | |
+ <span class="logo"><img | |
src="/styles/images/google_open_id.png"></span></li> | |
- <li class="open-id-provider" data-ng-class="{active: params.provider=='yahoo'}" | |
- data-ng-click="params.provider='yahoo'"><span class="logo"><img style="margin-bottom: .5rem" src="/styles/images/yahoo_open_id.png"></span> | |
- </li> | |
+ <li class="open-id-provider" data-ng-class="{active: params.provider=='yahoo'}"> | |
+ <span class="logo"><img style="margin-bottom: .5rem" src="/styles/images/yahoo_open_id.png"></span></li> | |
</ul> | |
- <!--<p data-ng-show="provider=='icgc'">Sign in using your <strong>ICGC</strong> account.<br><br>--> | |
- <!--<label>Username</label><br>--> | |
- <!--<input type="text" id="cudUsername" style="width:50%" data-ng-model="cudUsername">--> | |
- <!--<br>--> | |
- <!--<label>Paasword</label><br>--> | |
- <!--<input type="password" id="cudPassword" style="width:50%" data-ng-model="cudPassword">--> | |
- <!--</p>--> | |
+ <p data-ng-show="params.provider=='ohsu'">Sign in using your <strong>OHSU</strong> account.<br><br> | |
+ <label>Domain</label><br> | |
+ <input type="text" id="osDomain" style="width:50%" data-ng-model="params.osDomain"> | |
+ <br> | |
+ <label>Username</label><br> | |
+ <input type="text" id="osUsername" style="width:50%" data-ng-model="params.osUsername"> | |
+ <br> | |
+ <label>Password</label><br> | |
+ <input type="password" id="osPassword" style="width:50%" data-ng-model="params.osPassword"> | |
+ </p> | |
<p data-ng-show="params.provider=='icgc'"><translate has-markup>Sign in using your <strong>ICGC</strong> account.</translate></p> | |
@@ -65,4 +73,3 @@ | |
</button> | |
</div> | |
</div> | |
- | |
diff --git a/dcc-portal-ui/app/styles/images/ohsu-logo.png b/dcc-portal-ui/app/styles/images/ohsu-logo.png | |
new file mode 100644 | |
index 0000000..d8f103f | |
Binary files /dev/null and b/dcc-portal-ui/app/styles/images/ohsu-logo.png differ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment