mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Workin on login user state
This commit is contained in:
parent
4f798cfe56
commit
31398718e5
@ -11,10 +11,8 @@ function (angular, config, _, $, store) {
|
|||||||
var module = angular.module('grafana.controllers');
|
var module = angular.module('grafana.controllers');
|
||||||
|
|
||||||
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) {
|
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) {
|
||||||
|
|
||||||
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
|
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
|
||||||
$scope.consoleEnabled = store.getBool('grafanaConsole');
|
$scope.grafana = {};
|
||||||
$scope.showProSideMenu = store.getBool('grafanaProSideMenu');
|
|
||||||
|
|
||||||
$rootScope.profilingEnabled = store.getBool('profilingEnabled');
|
$rootScope.profilingEnabled = store.getBool('profilingEnabled');
|
||||||
$rootScope.performance = { loadStart: new Date().getTime() };
|
$rootScope.performance = { loadStart: new Date().getTime() };
|
||||||
@ -25,25 +23,27 @@ function (angular, config, _, $, store) {
|
|||||||
if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
|
if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
|
||||||
|
|
||||||
$scope.dashAlerts = alertSrv;
|
$scope.dashAlerts = alertSrv;
|
||||||
$scope.grafana = { style: 'dark' };
|
$scope.grafana.style = 'dark';
|
||||||
|
$scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
|
||||||
|
|
||||||
|
if (window.grafanaBootData.user.login) {
|
||||||
|
$scope.grafana.user = window.grafanaBootData.user;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.onAppEvent('logged-out', function() {
|
$scope.onAppEvent('logged-out', function() {
|
||||||
$scope.showProSideMenu = false;
|
$scope.showProSideMenu = false;
|
||||||
|
$scope.grafana.user = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.onAppEvent('logged-in', function() {
|
$scope.onAppEvent('logged-in', function(evt, user) {
|
||||||
$scope.showProSideMenu = store.getBool('grafanaProSideMenu');
|
$scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
|
||||||
|
$scope.grafana.user = user;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.toggleProSideMenu = function() {
|
$scope.toggleProSideMenu = function() {
|
||||||
$scope.showProSideMenu = !$scope.showProSideMenu;
|
$scope.grafana.sidemenu = !$scope.grafana.sidemenu;
|
||||||
store.set('grafanaProSideMenu', $scope.showProSideMenu);
|
store.set('grafana.sidemenu', $scope.grafana.sidemenu);
|
||||||
};
|
|
||||||
|
|
||||||
$scope.toggleConsole = function() {
|
|
||||||
$scope.consoleEnabled = !$scope.consoleEnabled;
|
|
||||||
store.set('grafanaConsole', $scope.consoleEnabled);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.onAppEvent = function(name, callback) {
|
$rootScope.onAppEvent = function(name, callback) {
|
||||||
|
@ -8,6 +8,7 @@ function (angular) {
|
|||||||
|
|
||||||
module.controller('LoginCtrl', function($scope, $http, $location, $routeParams, alertSrv) {
|
module.controller('LoginCtrl', function($scope, $http, $location, $routeParams, alertSrv) {
|
||||||
$scope.loginModel = {};
|
$scope.loginModel = {};
|
||||||
|
$scope.grafana.sidemenu = false;
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
if ($routeParams.logout) {
|
if ($routeParams.logout) {
|
||||||
@ -20,6 +21,7 @@ function (angular) {
|
|||||||
|
|
||||||
alertSrv.set('Logged out!', '', 'success', 3000);
|
alertSrv.set('Logged out!', '', 'success', 3000);
|
||||||
$scope.emitAppEvent('logged-out');
|
$scope.emitAppEvent('logged-out');
|
||||||
|
$location.search({});
|
||||||
|
|
||||||
}, function() {
|
}, function() {
|
||||||
alertSrv.set('Logout failed:', 'Unexpected error', 'error', 3000);
|
alertSrv.set('Logout failed:', 'Unexpected error', 'error', 3000);
|
||||||
@ -33,8 +35,8 @@ function (angular) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$http.post('/login', $scope.loginModel).then(function() {
|
$http.post('/login', $scope.loginModel).then(function(results) {
|
||||||
$scope.emitAppEvent('logged-in');
|
$scope.emitAppEvent('logged-in', results.data.user);
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err.status === 401) {
|
if (err.status === 401) {
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
<section class="pro-sidemenu-items">
|
<section class="pro-sidemenu-items">
|
||||||
<a class="pro-sidemenu-link" href="/login?logout">
|
<div class="dropdown">
|
||||||
<i class="icon-lock"></i>
|
<a class="pro-sidemenu-link pointer" data-toggle="dropdown">
|
||||||
logout
|
<i class="icon-user"></i>
|
||||||
</a>
|
{{grafana.user.login}}
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a href="/login?logout">Logout</a>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<a class="pro-sidemenu-link" href="/dashboard/db/home">
|
<a class="pro-sidemenu-link" href="/dashboard/db/home">
|
||||||
<i class="icon-th-large"></i>
|
<i class="icon-th-large"></i>
|
||||||
Dashboards
|
Dashboards
|
||||||
@ -27,6 +32,11 @@
|
|||||||
<i class="icon-user"></i>
|
<i class="icon-user"></i>
|
||||||
User accounts
|
User accounts
|
||||||
</a>
|
</a>
|
||||||
|
<a class="pro-sidemenu-link" href="/login?logout">
|
||||||
|
<i class="icon-signout"></i>
|
||||||
|
Sign out
|
||||||
|
</a>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,11 +21,9 @@ function (angular) {
|
|||||||
|
|
||||||
module.controller('RegisterCtrl', function($scope, $http, $location, $routeParams) {
|
module.controller('RegisterCtrl', function($scope, $http, $location, $routeParams) {
|
||||||
$scope.loginModel = {};
|
$scope.loginModel = {};
|
||||||
|
$scope.grafana.sidemenu = false;
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
if ($routeParams.logout) {
|
|
||||||
$scope.logout();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.register = function() {
|
$scope.register = function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user