You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2018/10/09 09:09:25 UTC
[21/27] lucene-solr:solr7896-login-page: WIP
WIP
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/7c964580
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/7c964580
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/7c964580
Branch: refs/heads/solr7896-login-page
Commit: 7c964580de6a1407d0371febdd709a8d7884bc8d
Parents: 9012e40
Author: Jan Høydahl <ja...@apache.org>
Authored: Mon Oct 8 12:48:45 2018 +0200
Committer: Jan Høydahl <ja...@apache.org>
Committed: Mon Oct 8 12:48:45 2018 +0200
----------------------------------------------------------------------
solr/webapp/web/index.html | 2 +-
solr/webapp/web/js/angular/app.js | 50 ++++++--------------
solr/webapp/web/js/angular/controllers/login.js | 11 -----
solr/webapp/web/js/angular/services.js | 27 +++++------
4 files changed, 28 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7c964580/solr/webapp/web/index.html
----------------------------------------------------------------------
diff --git a/solr/webapp/web/index.html b/solr/webapp/web/index.html
index 4b83533..0f1478f 100644
--- a/solr/webapp/web/index.html
+++ b/solr/webapp/web/index.html
@@ -141,7 +141,7 @@ limitations under the License.
<div>
<ul id="menu">
- <li id="login" class="global" ng-class="{active:page=='login'}"><p><a href="#/login">Logout {{username}}</a></p></li>
+ <li id="login" class="global" ng-class="{active:page=='login'}"><p><a href="#/login">Login {{$root.globals.currentUser.username}} {{$root.globals}}</a></p></li>
<li id="index" class="global" ng-class="{active:page=='index'}"><p><a href="#/">Dashboard</a></p></li>
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7c964580/solr/webapp/web/js/angular/app.js
----------------------------------------------------------------------
diff --git a/solr/webapp/web/js/angular/app.js b/solr/webapp/web/js/angular/app.js
index 36dd07c..3c29fc4 100644
--- a/solr/webapp/web/js/angular/app.js
+++ b/solr/webapp/web/js/angular/app.js
@@ -376,21 +376,18 @@ solrAdminApp.config([
// NOCOMMIT First iteration
.factory('authInterceptor', function($q, $rootScope, $location, $timeout, $injector) {
var started = function(config) {
- console.log("Request config: " + JSON.stringify(config, undefined, 2));
- // var ah = "Basic c29scjpyb2Nrcw=="; // solr / SolrRocks
- // config.headers['Authorization'] = ah;
- // console.log("Added authorization header " + ah);
- if (sessionStorage.getItem("auth.header") !== null) {
- if (config.headers['Authorization'] === null) {
- config.headers['Authorization'] = sessionStorage.getItem("auth.header");
- console.log("We have a logged in user with header " + sessionStorage.getItem("auth.username") + ", appending header");
- }
+ console.log("Request config headers: " + JSON.stringify(config.headers, undefined, 2));
+ if (sessionStorage.getItem("auth.header") && !config.headers['Authorization']) {
+ config.headers['Authorization'] = sessionStorage.getItem("auth.header");
+ console.log("We have a logged in user with header " + sessionStorage.getItem("auth.username") + ", appending header " + sessionStorage.getItem("auth.header"));
+ } else {
+ console.log("Not adding headers. Have auth.username=" + sessionStorage.getItem("auth.username") + ", auth.header=" + sessionStorage.getItem("auth.header") + ", config.headers=" + config.headers['Authorization']);
}
return config || $q.when(config);
};
var ended = function(response) {
- console.log("Response headers: " + JSON.stringify(response.headers(), undefined, 2));
+ // console.log("Response headers: " + JSON.stringify(response.headers(), undefined, 2));
return response || $q.when(response);
};
@@ -410,15 +407,19 @@ solrAdminApp.config([
var authType = wwwAuthHeader.split(" ")[0];
console.log("AuthType is: " + authType);
sessionStorage.setItem("auth.type", authType);
- sessionStorage.setItem("auth.location", $location.path());
+ if ($location.path() === '/login') {
+ sessionStorage.setItem("auth.location", "/");
+ } else {
+ sessionStorage.setItem("auth.location", $location.path());
+ }
sessionStorage.removeItem("auth.username");
sessionStorage.removeItem("auth.header");
+ // $http.defaults.headers.common.Authorization = null;
$location.path('/login');
} else {
console.log("Rejection status is " + rejection.status)
- }
- $rootScope.$broadcast('loadingStatusInactive');
- return $q.reject(rejection);
+ $rootScope.$broadcast('loadingStatusInactive');
+ return $q.reject(rejection); }
};
return {request: started, response: ended, responseError: failed};
@@ -429,27 +430,6 @@ solrAdminApp.config([
// Force BasicAuth plugin to serve us a 'Authorization: xBasic xxxx' header so browser will not pop up login dialogue
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
})
-
-
-// NOCOMMIT: just for testing
-// .run(['$rootScope', '$location', '$cookieStore', '$http',
-// function ($rootScope, $location, $cookieStore, $http) {
-// // keep user logged in after page refresh
-// // Replace with interceptor
-// $rootScope.globals = $cookieStore.get('globals') || {};
-// if ($rootScope.globals.currentUser) {
-// $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
-// }
-//
-// // $rootScope.$on('$locationChangeStart', function (event, next, current) {
-// // // redirect to login page if not logged in
-// // if ($location.path() !== '/login' && !$rootScope.globals.currentUser) {
-// // $location.path('/login');
-// // }
-// // });
-// }])
-
-
.directive('fileModel', function ($parse) {
return {
restrict: 'A',
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7c964580/solr/webapp/web/js/angular/controllers/login.js
----------------------------------------------------------------------
diff --git a/solr/webapp/web/js/angular/controllers/login.js b/solr/webapp/web/js/angular/controllers/login.js
index a67119c8..174a491 100644
--- a/solr/webapp/web/js/angular/controllers/login.js
+++ b/solr/webapp/web/js/angular/controllers/login.js
@@ -37,17 +37,6 @@ solrAdminApp.controller('LoginController',
AuthenticationService.SetCredentials($scope.username, $scope.password);
console.log("Redirecting back to " + $scope.authLocation);
$location.path($scope.authLocation); // Redirect to the location that caused the login prompt
-
- // TODO: "login" by hitting the failing URL again
- // AuthenticationService.Login($scope.username, $scope.password, function (response) {
- // if (response.success) {
- // AuthenticationService.SetCredentials($scope.username, $scope.password);
- // $location.path('/');
- // } else {
- // $scope.error = response.message;
- // $scope.dataLoading = false;
- // }
- // });
};
$scope.logout = function() {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7c964580/solr/webapp/web/js/angular/services.js
----------------------------------------------------------------------
diff --git a/solr/webapp/web/js/angular/services.js b/solr/webapp/web/js/angular/services.js
index 323bc8e..8f2d443 100644
--- a/solr/webapp/web/js/angular/services.js
+++ b/solr/webapp/web/js/angular/services.js
@@ -293,30 +293,27 @@ solrAdminServices.factory('System',
service.SetCredentials = function (username, password) {
var authdata = Base64.encode(username + ':' + password);
- sessionStorage.setItem("auth.username", username);
- $rootScope.username = username;
-
- $rootScope.globals = {
- currentUser: {
- username: username,
- authdata: authdata
- }
- };
-
- // $http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; // jshint ignore:line
- $http.defaults.headers.common.Authorization = 'Basic ' + authdata;
- // sessionStorage.setItem('globals', $rootScope.globals);
+ // $rootScope.globals = {
+ // currentUser: {
+ // username: username,
+ // authdata: authdata
+ // }
+ // };
+ //
+ sessionStorage.setItem('globals', $rootScope.globals);
sessionStorage.setItem("auth.header", authdata);
+ sessionStorage.setItem("auth.username", username);
+ // $http.defaults.headers.common.Authorization = authdata;
console.log("Stored auth data on session storage");
};
service.ClearCredentials = function () {
$rootScope.globals = {};
- // sessionStorage.removeItem('globals');
+ sessionStorage.removeItem('globals');
sessionStorage.removeItem("auth.header");
sessionStorage.removeItem("auth.username");
sessionStorage.removeItem("auth.wwwAuthHeader");
- $http.defaults.headers.common.Authorization = null;
+ // $http.defaults.headers.common.Authorization = null;
console.log("Cleared stored auth data");
};