mirror of https://gitee.com/bigwinds/arangodb
frontend login mechanism
This commit is contained in:
parent
36bc70a468
commit
7e2317e151
|
@ -132,19 +132,14 @@
|
|||
},
|
||||
|
||||
currentDatabase: function (callback) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
cache: false,
|
||||
url: this.databaseUrl("/_api/database/current"),
|
||||
contentType: "application/json",
|
||||
processData: false,
|
||||
success: function(data) {
|
||||
callback(false, data.result.name);
|
||||
},
|
||||
error: function(data) {
|
||||
callback(true, data);
|
||||
if (frontendConfig.db) {
|
||||
callback(false, frontendConfig.db);
|
||||
}
|
||||
});
|
||||
else {
|
||||
callback(true, undefined);
|
||||
}
|
||||
console.log(frontendConfig.db);
|
||||
return frontendConfig.db;
|
||||
},
|
||||
|
||||
allHotkeys: {
|
||||
|
@ -501,6 +496,7 @@
|
|||
}
|
||||
},
|
||||
error: function(data) {
|
||||
console.log("error");
|
||||
if (callback) {
|
||||
callback(true, data);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
$.ajax({
|
||||
type: "GET",
|
||||
cache: false,
|
||||
url: arangoHelper.databaseHelper("/_api/collection/" + this.get("id") + "/figures"),
|
||||
url: arangoHelper.databaseUrl("/_api/collection/" + this.get("id") + "/figures"),
|
||||
contentType: "application/json",
|
||||
processData: false,
|
||||
success: function(data) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*global Backbone, window, arangoHelper */
|
||||
/*global Backbone, window, arangoHelper, frontendConfig */
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
window.CurrentDatabase = Backbone.Model.extend({
|
||||
url: arangoHelper.databaseUrl("/_api/database/current"),
|
||||
url: arangoHelper.databaseUrl("/_api/database/current", frontendConfig.db),
|
||||
|
||||
parse: function(data) {
|
||||
return data.result;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*jshint unused: false */
|
||||
/*global window, $, Backbone, document, arangoCollectionModel*/
|
||||
/*global arangoHelper, btoa, dashboardView, arangoDatabase, _*/
|
||||
/*global arangoHelper, btoa, dashboardView, arangoDatabase, _, frontendConfig */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
@ -54,16 +54,38 @@
|
|||
},
|
||||
|
||||
checkUser: function () {
|
||||
|
||||
if (window.location.hash === '#login') {
|
||||
return;
|
||||
}
|
||||
|
||||
var startInit = function() {
|
||||
this.initOnce();
|
||||
|
||||
//show hidden by default divs
|
||||
$('.bodyWrapper').show();
|
||||
$('.navbar').show();
|
||||
}.bind(this);
|
||||
|
||||
var callback = function(error, user) {
|
||||
if (frontendConfig.authenticationEnabled) {
|
||||
if (error || user === null) {
|
||||
if (window.location.hash !== '#login') {
|
||||
this.navigate("login", {trigger: true});
|
||||
}
|
||||
}
|
||||
else {
|
||||
startInit();
|
||||
}
|
||||
}
|
||||
else {
|
||||
startInit();
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
if (frontendConfig.authenticationEnabled) {
|
||||
this.userCollection.whoAmI(callback);
|
||||
}
|
||||
else {
|
||||
this.initOnce();
|
||||
|
||||
|
@ -71,9 +93,6 @@
|
|||
$('.bodyWrapper').show();
|
||||
$('.navbar').show();
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
this.userCollection.whoAmI(callback);
|
||||
},
|
||||
|
||||
waitForInit: function(origin, param1, param2) {
|
||||
|
@ -88,7 +107,7 @@
|
|||
if (param1 && param2) {
|
||||
origin(param1, param2, false);
|
||||
}
|
||||
}, 250);
|
||||
}, 350);
|
||||
} else {
|
||||
if (!param1) {
|
||||
origin(true);
|
||||
|
@ -123,7 +142,7 @@
|
|||
|
||||
var callback = function(error, isCoordinator) {
|
||||
self = this;
|
||||
if (isCoordinator) {
|
||||
if (isCoordinator === true) {
|
||||
self.isCluster = true;
|
||||
|
||||
self.coordinatorCollection.fetch({
|
||||
|
@ -209,11 +228,11 @@
|
|||
|
||||
cluster: function (initialized) {
|
||||
this.checkUser();
|
||||
if (!initialized || this.isCluster === undefined) {
|
||||
if (!initialized) {
|
||||
this.waitForInit(this.cluster.bind(this));
|
||||
return;
|
||||
}
|
||||
if (this.isCluster === false) {
|
||||
if (this.isCluster === false || this.isCluster === undefined) {
|
||||
if (this.currentDB.get("name") === '_system') {
|
||||
this.routes[""] = 'dashboard';
|
||||
this.navigate("#dashboard", {trigger: true});
|
||||
|
@ -409,16 +428,16 @@
|
|||
login: function () {
|
||||
|
||||
var callback = function(error, user) {
|
||||
if (error || user === null) {
|
||||
if (!this.loginView) {
|
||||
this.loginView = new window.loginView({
|
||||
collection: this.userCollection
|
||||
});
|
||||
}
|
||||
if (error || user === null) {
|
||||
this.loginView.render();
|
||||
}
|
||||
else {
|
||||
this.navigate("", {trigger: true});
|
||||
this.loginView.render(true);
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
|
|
|
@ -4,22 +4,21 @@
|
|||
<li class="subMenuEntry pull-left">
|
||||
<div class="breadcrumb"></div>
|
||||
</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="state health-state">GOOD</a>
|
||||
<a class="icon health-icon">
|
||||
<i class="fa fa-check-circle"></i>
|
||||
</a>
|
||||
</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"><%= 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 id="userBar" class="infoEntry subMenuEntry pull-right" style="margin-right: 10px;">
|
||||
<!--
|
||||
<div class="usermenu" id="userBar"></div>
|
||||
<div class="notificationmenu" id="notificationBar"></div>
|
||||
-->
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<script id="userBarView.ejs" type="text/template">
|
||||
|
||||
<a class="info">User:
|
||||
<a class="info default-icon">User:
|
||||
<span class="toggle">
|
||||
<%=_.escape(username)%>
|
||||
</span>
|
||||
<i id="userLogoutIcon" class="fa fa-power-off" aria-hidden="true"></i>
|
||||
</a>
|
||||
|
||||
<ul id="userInfo" class="subBarDropdown">
|
||||
|
|
|
@ -1008,13 +1008,21 @@
|
|||
}
|
||||
}.bind(this);
|
||||
|
||||
if (window.App.currentDB.get("name") === undefined) {
|
||||
window.setTimeout(function() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
|
|
@ -20,13 +20,37 @@
|
|||
|
||||
template: templateEngine.createTemplate("loginView.ejs"),
|
||||
|
||||
render: function() {
|
||||
render: function(loggedIn) {
|
||||
var self = this;
|
||||
|
||||
$(this.el).html(this.template.render({}));
|
||||
$(this.el2).hide();
|
||||
$(this.el3).hide();
|
||||
$('.bodyWrapper').show();
|
||||
|
||||
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;
|
||||
},
|
||||
|
@ -108,6 +132,9 @@
|
|||
e.preventDefault();
|
||||
var username = $('#loginUsername').val();
|
||||
var database = $('#loginDatabase').val();
|
||||
console.log(window.App.dbSet);
|
||||
window.App.dbSet = database;
|
||||
console.log(window.App.dbSet);
|
||||
|
||||
var callback2 = function(error) {
|
||||
if (error) {
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
renderFirst: true,
|
||||
activeSubMenu: undefined,
|
||||
|
||||
changeDB: function() {
|
||||
window.location.hash = '#login';
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
|
||||
var self = this;
|
||||
|
@ -96,6 +100,10 @@
|
|||
$('.arangodbLogo').on('click', function() {
|
||||
self.selectMenuItem();
|
||||
});
|
||||
|
||||
$('#dbStatus').on('click', function() {
|
||||
self.changeDB();
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*jshint browser: true */
|
||||
/*jshint unused: false */
|
||||
/*global arangoHelper, Backbone, templateEngine, $, window*/
|
||||
/*global frontendConfig, arangoHelper, Backbone, templateEngine, $, window*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
|||
"click .tab" : "navigateByTab",
|
||||
"mouseenter .dropdown" : "showDropdown",
|
||||
"mouseleave .dropdown" : "hideDropdown",
|
||||
"click #userLogoutIcon" : "userLogout",
|
||||
"click #userLogout" : "userLogout"
|
||||
},
|
||||
|
||||
|
@ -53,6 +54,11 @@
|
|||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
if (frontendConfig.authenticationEnabled === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
var callback = function(error, username) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*jshint browser: true */
|
||||
/*jshint unused: false */
|
||||
/*global _, window, document, Backbone, EJS, SwaggerUi, hljs, $, arangoHelper, templateEngine,
|
||||
/*global frontendConfig, _, window, document, Backbone, EJS, SwaggerUi, hljs, $, arangoHelper, templateEngine,
|
||||
CryptoJS, Joi */
|
||||
(function() {
|
||||
|
||||
|
@ -37,12 +37,14 @@
|
|||
initialize: function() {
|
||||
var self = this,
|
||||
callback = function(error, user) {
|
||||
if (frontendConfig.authenticationEnabled === true) {
|
||||
if (error || user === null) {
|
||||
arangoHelper.arangoError("User", "Could not fetch user data");
|
||||
}
|
||||
else {
|
||||
this.currentUser = this.collection.findWhere({user: user});
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
//fetch collection defined in router
|
||||
|
|
Loading…
Reference in New Issue