1
0
Fork 0

frontend login mechanism

This commit is contained in:
hkernbach 2016-05-19 16:14:20 +02:00
parent 36bc70a468
commit 7e2317e151
11 changed files with 125 additions and 59 deletions

View File

@ -132,19 +132,14 @@
}, },
currentDatabase: function (callback) { currentDatabase: function (callback) {
$.ajax({ if (frontendConfig.db) {
type: "GET", callback(false, frontendConfig.db);
cache: false, }
url: this.databaseUrl("/_api/database/current"), else {
contentType: "application/json", callback(true, undefined);
processData: false, }
success: function(data) { console.log(frontendConfig.db);
callback(false, data.result.name); return frontendConfig.db;
},
error: function(data) {
callback(true, data);
}
});
}, },
allHotkeys: { allHotkeys: {
@ -501,6 +496,7 @@
} }
}, },
error: function(data) { error: function(data) {
console.log("error");
if (callback) { if (callback) {
callback(true, data); callback(true, data);
} }

View File

@ -36,7 +36,7 @@
$.ajax({ $.ajax({
type: "GET", type: "GET",
cache: false, cache: false,
url: arangoHelper.databaseHelper("/_api/collection/" + this.get("id") + "/figures"), url: arangoHelper.databaseUrl("/_api/collection/" + this.get("id") + "/figures"),
contentType: "application/json", contentType: "application/json",
processData: false, processData: false,
success: function(data) { success: function(data) {

View File

@ -1,10 +1,10 @@
/*global Backbone, window, arangoHelper */ /*global Backbone, window, arangoHelper, frontendConfig */
(function() { (function() {
"use strict"; "use strict";
window.CurrentDatabase = Backbone.Model.extend({ window.CurrentDatabase = Backbone.Model.extend({
url: arangoHelper.databaseUrl("/_api/database/current"), url: arangoHelper.databaseUrl("/_api/database/current", frontendConfig.db),
parse: function(data) { parse: function(data) {
return data.result; return data.result;

View File

@ -1,6 +1,6 @@
/*jshint unused: false */ /*jshint unused: false */
/*global window, $, Backbone, document, arangoCollectionModel*/ /*global window, $, Backbone, document, arangoCollectionModel*/
/*global arangoHelper, btoa, dashboardView, arangoDatabase, _*/ /*global arangoHelper, btoa, dashboardView, arangoDatabase, _, frontendConfig */
(function () { (function () {
"use strict"; "use strict";
@ -54,26 +54,45 @@
}, },
checkUser: function () { checkUser: function () {
if (window.location.hash === '#login') { if (window.location.hash === '#login') {
return; return;
} }
var startInit = function() {
this.initOnce();
//show hidden by default divs
$('.bodyWrapper').show();
$('.navbar').show();
}.bind(this);
var callback = function(error, user) { var callback = function(error, user) {
if (error || user === null) { if (frontendConfig.authenticationEnabled) {
if (window.location.hash !== '#login') { if (error || user === null) {
this.navigate("login", {trigger: true}); if (window.location.hash !== '#login') {
this.navigate("login", {trigger: true});
}
}
else {
startInit();
} }
} }
else { else {
this.initOnce(); startInit();
//show hidden by default divs
$('.bodyWrapper').show();
$('.navbar').show();
} }
}.bind(this); }.bind(this);
this.userCollection.whoAmI(callback); if (frontendConfig.authenticationEnabled) {
this.userCollection.whoAmI(callback);
}
else {
this.initOnce();
//show hidden by default divs
$('.bodyWrapper').show();
$('.navbar').show();
}
}, },
waitForInit: function(origin, param1, param2) { waitForInit: function(origin, param1, param2) {
@ -88,7 +107,7 @@
if (param1 && param2) { if (param1 && param2) {
origin(param1, param2, false); origin(param1, param2, false);
} }
}, 250); }, 350);
} else { } else {
if (!param1) { if (!param1) {
origin(true); origin(true);
@ -123,7 +142,7 @@
var callback = function(error, isCoordinator) { var callback = function(error, isCoordinator) {
self = this; self = this;
if (isCoordinator) { if (isCoordinator === true) {
self.isCluster = true; self.isCluster = true;
self.coordinatorCollection.fetch({ self.coordinatorCollection.fetch({
@ -209,11 +228,11 @@
cluster: function (initialized) { cluster: function (initialized) {
this.checkUser(); this.checkUser();
if (!initialized || this.isCluster === undefined) { if (!initialized) {
this.waitForInit(this.cluster.bind(this)); this.waitForInit(this.cluster.bind(this));
return; return;
} }
if (this.isCluster === false) { if (this.isCluster === false || this.isCluster === undefined) {
if (this.currentDB.get("name") === '_system') { if (this.currentDB.get("name") === '_system') {
this.routes[""] = 'dashboard'; this.routes[""] = 'dashboard';
this.navigate("#dashboard", {trigger: true}); this.navigate("#dashboard", {trigger: true});
@ -409,16 +428,16 @@
login: function () { login: function () {
var callback = function(error, user) { var callback = function(error, user) {
if (!this.loginView) {
this.loginView = new window.loginView({
collection: this.userCollection
});
}
if (error || user === null) { if (error || user === null) {
if (!this.loginView) {
this.loginView = new window.loginView({
collection: this.userCollection
});
}
this.loginView.render(); this.loginView.render();
} }
else { else {
this.navigate("", {trigger: true}); this.loginView.render(true);
} }
}.bind(this); }.bind(this);

View File

@ -4,22 +4,21 @@
<li class="subMenuEntry pull-left"> <li class="subMenuEntry pull-left">
<div class="breadcrumb"></div> <div class="breadcrumb"></div>
</li> </li>
<li id="healthStatus" class="infoEntry subMenuEntry pull-right"> <li id="healthStatus" class="infoEntry subMenuEntry pull-right positive">
<a class="info health-info">HEALTH: </a> <a class="info health-info">HEALTH: </a>
<a class="state health-state">GOOD</a> <a class="state health-state">GOOD</a>
<a class="icon health-icon"> <a class="icon health-icon">
<i class="fa fa-check-circle"></i> <i class="fa fa-check-circle"></i>
</a> </a>
</li> </li>
<li id="dbStatus" class="infoEntry subMenuEntry pull-right"> <li id="dbStatus" class="infoEntry subMenuEntry pull-right positive">
<a class="info">DB:</a> <a class="info">DB:</a>
<a class="info"><%= currentDB.name %> </a> <a class="state"><span><%= currentDB.name %></span></a>
<a class="icon db-icon default-icon">
<i class="fa fa-refresh"></i>
</a>
</li> </li>
<li id="userBar" class="infoEntry subMenuEntry pull-right" style="margin-right: 10px;"> <li id="userBar" class="infoEntry subMenuEntry pull-right" style="margin-right: 10px;">
<!--
<div class="usermenu" id="userBar"></div>
<div class="notificationmenu" id="notificationBar"></div>
-->
</li> </li>
</ul> </ul>

View File

@ -1,9 +1,10 @@
<script id="userBarView.ejs" type="text/template"> <script id="userBarView.ejs" type="text/template">
<a class="info">User: <a class="info default-icon">User:
<span class="toggle"> <span class="toggle">
<%=_.escape(username)%> <%=_.escape(username)%>
</span> </span>
<i id="userLogoutIcon" class="fa fa-power-off" aria-hidden="true"></i>
</a> </a>
<ul id="userInfo" class="subBarDropdown"> <ul id="userInfo" class="subBarDropdown">

View File

@ -1008,13 +1008,21 @@
} }
}.bind(this); }.bind(this);
if (window.App.currentDB.get("name") !== '_system') { if (window.App.currentDB.get("name") === undefined) {
errorFunction(); window.setTimeout(function() {
return; if (window.App.currentDB.get("name") !== '_system') {
errorFunction();
return;
}
//check if user has _system permission
this.options.database.hasSystemAccess(callback2);
}.bind(this), 300);
}
else {
//check if user has _system permission
this.options.database.hasSystemAccess(callback2);
} }
//check if user has _system permission
this.options.database.hasSystemAccess(callback2);
} }
}); });
}()); }());

View File

@ -20,13 +20,37 @@
template: templateEngine.createTemplate("loginView.ejs"), template: templateEngine.createTemplate("loginView.ejs"),
render: function() { render: function(loggedIn) {
var self = this;
$(this.el).html(this.template.render({})); $(this.el).html(this.template.render({}));
$(this.el2).hide(); $(this.el2).hide();
$(this.el3).hide(); $(this.el3).hide();
$('.bodyWrapper').show();
$('#loginUsername').focus(); if (frontendConfig.authenticationEnabled && loggedIn !== true) {
$('#loginUsername').focus();
}
else {
$('#logout').hide();
$('.login-window #databases').css('height', '90px');
$('#loginForm').hide();
$('.login-window #databases').show();
$.ajax(arangoHelper.databaseUrl("/_api/database/")).success(function(data) {
//enable db select and login button
$('#loginDatabase').html('');
//fill select with allowed dbs
_.each(data.result, function(db) {
$('#loginDatabase').append(
'<option>' + db + '</option>'
);
});
self.renderDBS();
});
}
$('.bodyWrapper').show();
return this; return this;
}, },
@ -108,6 +132,9 @@
e.preventDefault(); e.preventDefault();
var username = $('#loginUsername').val(); var username = $('#loginUsername').val();
var database = $('#loginDatabase').val(); var database = $('#loginDatabase').val();
console.log(window.App.dbSet);
window.App.dbSet = database;
console.log(window.App.dbSet);
var callback2 = function(error) { var callback2 = function(error) {
if (error) { if (error) {

View File

@ -20,6 +20,10 @@
renderFirst: true, renderFirst: true,
activeSubMenu: undefined, activeSubMenu: undefined,
changeDB: function() {
window.location.hash = '#login';
},
initialize: function (options) { initialize: function (options) {
var self = this; var self = this;
@ -96,6 +100,10 @@
$('.arangodbLogo').on('click', function() { $('.arangodbLogo').on('click', function() {
self.selectMenuItem(); self.selectMenuItem();
}); });
$('#dbStatus').on('click', function() {
self.changeDB();
});
} }
return this; return this;

View File

@ -1,6 +1,6 @@
/*jshint browser: true */ /*jshint browser: true */
/*jshint unused: false */ /*jshint unused: false */
/*global arangoHelper, Backbone, templateEngine, $, window*/ /*global frontendConfig, arangoHelper, Backbone, templateEngine, $, window*/
(function () { (function () {
"use strict"; "use strict";
@ -11,6 +11,7 @@
"click .tab" : "navigateByTab", "click .tab" : "navigateByTab",
"mouseenter .dropdown" : "showDropdown", "mouseenter .dropdown" : "showDropdown",
"mouseleave .dropdown" : "hideDropdown", "mouseleave .dropdown" : "hideDropdown",
"click #userLogoutIcon" : "userLogout",
"click #userLogout" : "userLogout" "click #userLogout" : "userLogout"
}, },
@ -53,6 +54,11 @@
}, },
render: function () { render: function () {
if (frontendConfig.authenticationEnabled === false) {
return;
}
var self = this; var self = this;
var callback = function(error, username) { var callback = function(error, username) {

View File

@ -1,6 +1,6 @@
/*jshint browser: true */ /*jshint browser: true */
/*jshint unused: false */ /*jshint unused: false */
/*global _, window, document, Backbone, EJS, SwaggerUi, hljs, $, arangoHelper, templateEngine, /*global frontendConfig, _, window, document, Backbone, EJS, SwaggerUi, hljs, $, arangoHelper, templateEngine,
CryptoJS, Joi */ CryptoJS, Joi */
(function() { (function() {
@ -37,11 +37,13 @@
initialize: function() { initialize: function() {
var self = this, var self = this,
callback = function(error, user) { callback = function(error, user) {
if (error || user === null) { if (frontendConfig.authenticationEnabled === true) {
arangoHelper.arangoError("User", "Could not fetch user data"); if (error || user === null) {
} arangoHelper.arangoError("User", "Could not fetch user data");
else { }
this.currentUser = this.collection.findWhere({user: user}); else {
this.currentUser = this.collection.findWhere({user: user});
}
} }
}.bind(this); }.bind(this);