1
0
Fork 0

Merge branch 'devel' of https://github.com/arangodb/arangodb into devel

This commit is contained in:
Kaveh Vahedipour 2017-01-16 14:10:20 +01:00
commit bb5b701d93
4 changed files with 99 additions and 53 deletions

View File

@ -56,6 +56,8 @@ edge attribute `label`.
v3.1.9 (XXXX-XX-XX)
-------------------
* ui: fixed re-login issue within a non system db, when tab was closed
* fixed a race in the VelocyStream Commtask implementation
* fixed issue #2256

View File

@ -48,8 +48,13 @@
return localStorage.getItem('jwt');
},
setCurrentJwt: function (jwt) {
getCurrentJwtUsername: function () {
return localStorage.getItem('jwtUser');
},
setCurrentJwt: function (jwt, username) {
localStorage.setItem('jwt', jwt);
localStorage.setItem('jwtUser', username);
},
lastNotificationMessage: null,

View File

@ -51,9 +51,8 @@ window.ArangoUsers = Backbone.Collection.extend({
dataType: 'json'
}).success(
function (data) {
arangoHelper.setCurrentJwt(data.jwt);
var jwtParts = data.jwt.split('.');
if (!jwtParts[1]) {
throw new Error('Invalid JWT');
}
@ -61,14 +60,21 @@ window.ArangoUsers = Backbone.Collection.extend({
if (!window.atob) {
throw new Error('base64 support missing in browser');
}
var payload = JSON.parse(atob(jwtParts[1]));
var payload = JSON.parse(atob(jwtParts[1]));
self.activeUser = payload.preferred_username;
if (self.activeUser === undefined) {
arangoHelper.setCurrentJwt(data.jwt, null);
} else {
arangoHelper.setCurrentJwt(data.jwt, self.activeUser);
}
callback(false, self.activeUser);
}
).error(
function () {
arangoHelper.setCurrentJwt(null);
arangoHelper.setCurrentJwt(null, null);
self.activeUser = null;
callback(true, null);
}

View File

@ -23,17 +23,17 @@
render: function (loggedIn) {
var self = this;
$(this.el).html(this.template.render({}));
$(this.el2).hide();
$(this.el3).hide();
if (frontendConfig.authenticationEnabled && loggedIn !== true) {
window.setTimeout(function () {
$('#loginUsername').focus();
}, 300);
} else {
var url = arangoHelper.databaseUrl('/_api/database/user');
var continueRender = function (user, errCallback) {
var url;
if (!user) {
url = arangoHelper.databaseUrl('/_api/database/user');
} else {
url = arangoHelper.databaseUrl('/_api/user/' + encodeURIComponent(user) + '/database', '_system');
}
if (frontendConfig.authenticationEnabled === false) {
$('#logout').hide();
@ -47,17 +47,45 @@
// enable db select and login button
$('#loginDatabase').html('');
// fill select with allowed dbs
_.each(permissions.result, function (db) {
$('#loginDatabase').append(
'<option>' + db + '</option>'
);
_.each(permissions.result, function (rule, db) {
if (errCallback) {
$('#loginDatabase').append(
'<option>' + db + '</option>'
);
} else {
$('#loginDatabase').append(
'<option>' + rule + '</option>'
);
}
});
self.renderDBS();
}).error(function () {
console.log('could not fetch user db data');
if (errCallback) {
errCallback();
} else {
console.log('could not fetch user db data');
}
});
};
if (frontendConfig.authenticationEnabled && loggedIn !== true) {
var usr = arangoHelper.getCurrentJwtUsername();
if (usr !== null && usr !== 'undefined' && usr !== undefined) {
// try if existent jwt is valid
var errCallback = function () {
window.setTimeout(function () {
$('#loginUsername').focus();
}, 300);
};
continueRender(arangoHelper.getCurrentJwtUsername(), errCallback);
} else {
window.setTimeout(function () {
$('#loginUsername').focus();
}, 300);
}
} else {
continueRender();
}
$('.bodyWrapper').show();
@ -132,44 +160,49 @@
'<option>_system</option>'
);
} else {
var url = arangoHelper.databaseUrl('/_api/user/' + encodeURIComponent(username) + '/database', '_system');
if (frontendConfig.authenticationEnabled === false) {
url = arangoHelper.databaseUrl('/_api/database/user');
}
$('.wrong-credentials').hide();
self.loggedIn = true;
// get list of allowed dbs
$.ajax(url).success(function (permissions) {
// HANDLE PERMISSIONS
_.each(permissions.result, function (value, key) {
if (value !== 'rw') {
delete permissions.result[key];
}
});
$('#loginForm').hide();
$('.login-window #databases').show();
// enable db select and login button
$('#loginDatabase').html('');
// fill select with allowed dbs
_.each(permissions.result, function (db, key) {
$('#loginDatabase').append(
'<option>' + key + '</option>'
);
});
self.renderDBS();
}).error(function () {
$('.wrong-credentials').show();
});
self.renderDBSelection(username);
}
},
renderDBSelection: function (username) {
var self = this;
var url = arangoHelper.databaseUrl('/_api/user/' + encodeURIComponent(username) + '/database', '_system');
if (frontendConfig.authenticationEnabled === false) {
url = arangoHelper.databaseUrl('/_api/database/user');
}
$('.wrong-credentials').hide();
self.loggedIn = true;
// get list of allowed dbs
$.ajax(url).success(function (permissions) {
// HANDLE PERMISSIONS
_.each(permissions.result, function (value, key) {
if (value !== 'rw') {
delete permissions.result[key];
}
});
$('#loginForm').hide();
$('.login-window #databases').show();
// enable db select and login button
$('#loginDatabase').html('');
// fill select with allowed dbs
_.each(permissions.result, function (db, key) {
$('#loginDatabase').append(
'<option>' + key + '</option>'
);
});
self.renderDBS();
}).error(function () {
$('.wrong-credentials').show();
});
},
renderDBS: function () {
if ($('#loginDatabase').children().length === 0) {
$('#dbForm').remove();