зеркало из https://github.com/mozilla/treeherder.git
Bug 1159167 - Update to latest django-browserid
The latest version of django-browserid removes a view that we used to fetch to retrieve basig config params for the browserid client initialization. We now have loginUrl and logoutUrl hardcoded in the client and we fetch the user login status from a dedicated endpoint.
This commit is contained in:
Родитель
11c87d2174
Коммит
caebeeb794
|
@ -64,8 +64,8 @@ drf-extensions==0.2.7
|
|||
# sha256: _NluK-R8ju80xlDgB6bVRuGefuYQQbie27u-dhmqOYc
|
||||
django-cors-headers==1.1.0
|
||||
|
||||
# sha256: DVwMS2xs2dJb59eoJqXAxEzwQKEn2Sb4pX6mvnTrypg
|
||||
django-browserid==0.10
|
||||
# sha256: -jPrQhcqGbcVrbp6ZJcJEftdj9G2nPjaepXyvH8PMDs
|
||||
django-browserid==1.0.0
|
||||
|
||||
# sha256: gqOPZ02h-klsD8TfcUy7BYVAvtcqMMUKLjRLDZhMTSE
|
||||
oauth2==1.5.211
|
||||
|
|
|
@ -10,16 +10,14 @@ treeherder.directive('personaButtons', [
|
|||
return {
|
||||
restrict: "E",
|
||||
link: function(scope, element, attrs) {
|
||||
BrowserId.info.then(function(response){
|
||||
scope.initialized = ThUserModel.get().then(function(user){
|
||||
$rootScope.user = {};
|
||||
// if the user.email value is null, it means that he's not logged in
|
||||
$rootScope.user.email = response.data.userEmail || null;
|
||||
$rootScope.user.email = user.email || null;
|
||||
$rootScope.user.loggedin = $rootScope.user.email !== null;
|
||||
|
||||
if ($rootScope.user.loggedin) {
|
||||
ThUserModel.get().then(function(user){
|
||||
angular.extend($rootScope.user, user);
|
||||
}, null);
|
||||
angular.extend($rootScope.user, user);
|
||||
}
|
||||
}).then(function(){
|
||||
navigator.id.watch({
|
||||
|
@ -57,22 +55,26 @@ treeherder.directive('personaButtons', [
|
|||
* BrowserID.login returns a promise of the verification.
|
||||
* If successful, we will find the user email in the response
|
||||
*/
|
||||
BrowserId.login()
|
||||
.then(function(response){
|
||||
$rootScope.user.loggedin = true;
|
||||
$rootScope.user.email = response.data.email;
|
||||
// retrieve the current user's info from the api
|
||||
ThUserModel.get().then(function(user){
|
||||
angular.extend($rootScope.user, user);
|
||||
}, null);
|
||||
},function(){
|
||||
// logout if the verification failed
|
||||
scope.logout();
|
||||
});
|
||||
scope.initialized.then(function(){
|
||||
BrowserId.login()
|
||||
.then(function(response){
|
||||
$rootScope.user.loggedin = true;
|
||||
$rootScope.user.email = response.data.email;
|
||||
// retrieve the current user's info from the api
|
||||
ThUserModel.get().then(function(user){
|
||||
angular.extend($rootScope.user, user);
|
||||
}, null);
|
||||
},function(){
|
||||
// logout if the verification failed
|
||||
scope.logout();
|
||||
});
|
||||
});
|
||||
};
|
||||
scope.logout = function(){
|
||||
BrowserId.logout().then(function(response){
|
||||
$rootScope.user = {loggedin: false, email:null};
|
||||
scope.initialized.then(function(){
|
||||
BrowserId.logout().then(function(response){
|
||||
$rootScope.user = {loggedin: false, email:null};
|
||||
});
|
||||
});
|
||||
};
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ treeherder.factory('ThUserModel', [
|
|||
if(response.data.length > 0){
|
||||
return new ThUserModel(response.data[0]);
|
||||
}else{
|
||||
return $q.reject({"data": "User not found"});
|
||||
return {};
|
||||
}
|
||||
}, function(reason){
|
||||
thNotify.send(reason.data,"danger");
|
||||
|
|
|
@ -102,7 +102,6 @@ treeherder.factory('BrowserId', [
|
|||
* This is mostly inspired by the django_browserid jquery implementation.
|
||||
*/
|
||||
var browserid = {
|
||||
info: $http.get(thServiceDomain+'/browserid/info/'),
|
||||
requestDeferred: null,
|
||||
logoutDeferred: null,
|
||||
|
||||
|
@ -111,12 +110,11 @@ treeherder.factory('BrowserId', [
|
|||
* and send it to the treeherder verification endpoints.
|
||||
*
|
||||
*/
|
||||
login: function(requestArgs){
|
||||
return browserid.getAssertion(requestArgs)
|
||||
login: function(){
|
||||
return browserid.getAssertion()
|
||||
.then(function(response) {
|
||||
return browserid.verifyAssertion(response);
|
||||
});
|
||||
|
||||
},
|
||||
/*
|
||||
* Logout from persona and notify treeherder of the change
|
||||
|
@ -124,12 +122,10 @@ treeherder.factory('BrowserId', [
|
|||
* of navigator.id.watch
|
||||
*/
|
||||
logout: function(){
|
||||
return browserid.info.then(function(response){
|
||||
browserid.logoutDeferred = $q.defer();
|
||||
navigator.id.logout();
|
||||
return browserid.logoutDeferred.promise.then(function(){
|
||||
return $http.post(response.data.logoutUrl);
|
||||
});
|
||||
browserid.logoutDeferred = $q.defer();
|
||||
navigator.id.logout();
|
||||
return browserid.logoutDeferred.promise.then(function(){
|
||||
return $http.post(thServiceDomain+'/browserid/logout/');
|
||||
});
|
||||
},
|
||||
/*
|
||||
|
@ -137,25 +133,20 @@ treeherder.factory('BrowserId', [
|
|||
* The requestDeferred promise is resolved by the onLogin callback
|
||||
* of navigator.id.watch.
|
||||
*/
|
||||
getAssertion: function(requestArgs){
|
||||
return browserid.info.then(function(response){
|
||||
requestArgs = _.extend({}, response.data.requestArgs, requestArgs);
|
||||
browserid.requestDeferred = $q.defer();
|
||||
navigator.id.request(requestArgs);
|
||||
return browserid.requestDeferred.promise;
|
||||
});
|
||||
getAssertion: function(){
|
||||
browserid.requestDeferred = $q.defer();
|
||||
navigator.id.request();
|
||||
return browserid.requestDeferred.promise;
|
||||
},
|
||||
/*
|
||||
* Verify the assertion provided by persona against the treeherder verification endpoint.
|
||||
* The django_browserid endpoint accept a post request with form-urlencoded fields.
|
||||
*/
|
||||
verifyAssertion: function(assertion){
|
||||
return browserid.info.then(function(response){
|
||||
return $http.post(
|
||||
response.data.loginUrl, {assertion: assertion},{
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
|
||||
transformRequest: browserid.transform_data
|
||||
});
|
||||
return $http.post(
|
||||
thServiceDomain+'/browserid/login/', {assertion: assertion},{
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
|
||||
transformRequest: browserid.transform_data
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче