From d0bed78d02852b2d27f7afe163c1d183eb5bc94c Mon Sep 17 00:00:00 2001 From: luccioman Date: Tue, 24 Oct 2017 09:34:03 +0200 Subject: [PATCH] Use the same top nav bar on index.html and search results. Thus eventually including the same optional login link/status in the search start page than in the results page, for the same convenient login without the need to use the Administration section. --- htroot/index.html | 2 +- htroot/index.java | 50 +++++++++++++++++++++++++++++++++++++++--- htroot/yacysearch.java | 3 +-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/htroot/index.html b/htroot/index.html index 7ee2dbcfc..5af481042 100644 --- a/htroot/index.html +++ b/htroot/index.html @@ -41,7 +41,7 @@ #(topmenu)# #%env/templates/embeddedheader.template%# :: - #%env/templates/simpleheader.template%# + #%env/templates/simpleSearchHeader.template%# diff --git a/htroot/index.java b/htroot/index.java index 3a03e8a52..725929037 100644 --- a/htroot/index.java +++ b/htroot/index.java @@ -52,9 +52,15 @@ public class index { } // access control - final boolean authorizedAccess = sb.verifyAuthentication(header); - if ((post != null) && (post.containsKey("publicPage"))) { - if (!authorizedAccess) { + String authenticatedUserName = null; + final boolean adminAuthenticated = sb.verifyAuthentication(header); + + if(adminAuthenticated) { + authenticatedUserName = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin"); + } + + if ((post != null) && (post.containsKey("auth") || post.containsKey("publicPage"))) { + if (!adminAuthenticated) { prop.authenticationRequired(); return prop; } @@ -136,9 +142,47 @@ public class index { prop.put("searchdomswitches_searchapp_check", (contentdom == ContentDomain.APP) ? "1" : "0"); prop.put("search.navigation", sb.getConfig("search.navigation", "all") ); prop.put("search.verify", sb.getConfig("search.verify", "iffresh") ); + + handleTopNavBarLoginSection(header, sb, prop, authenticatedUserName); + // online caution timing sb.localSearchLastAccess = System.currentTimeMillis(); return prop; } + + /** + * Add any eventually relevant information to generate the proper login link or status in the top navigation bar + * @param header the current request headers + * @param sb the server environment + * @param prop the servlet answer object + * @param authenticatedUserName the name of the currently authenticated user or null + */ + private static void handleTopNavBarLoginSection(final RequestHeader header, final Switchboard sb, + final serverObjects prop, String authenticatedUserName) { + final boolean showLogin = sb.getConfigBool(SwitchboardConstants.SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN, + SwitchboardConstants.SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN_DEFAULT); + if(showLogin) { + if(authenticatedUserName != null) { + /* Show the name of the authenticated user */ + prop.put("showLogin", 1); + prop.put("showLogin_userName", authenticatedUserName); + } else { + /* Show a login link */ + prop.put("showLogin", 2); + + /* The login link targets the same URL as the current location, just adding the 'auth' parameter to indicates that access to extended search features is desired */ + StringBuilder loginURL = new StringBuilder("index.html?auth"); + final String query = header.getQueryString(); + if(query != null) { + loginURL.append("&").append(query); + } + + + prop.put("showLogin_loginURL", loginURL.toString()); + } + } else { + prop.put("showLogin", 0); + } + } } diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 17626528f..8f07e8244 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -109,8 +109,7 @@ public class yacysearch { if(adminAuthenticated) { authenticatedUserName = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin"); - } - if (!extendedSearchRights) { + } else { final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null; if(user != null) { extendedSearchRights = user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT);