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.
pull/135/head
luccioman 7 years ago
parent d8eaf621cc
commit d0bed78d02

@ -41,7 +41,7 @@
#(topmenu)#
#%env/templates/embeddedheader.template%#
::
#%env/templates/simpleheader.template%#
#%env/templates/simpleSearchHeader.template%#
<script type="text/javascript">
document.getElementById("header_websearch").className += " active";
</script>

@ -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);
}
}
}

@ -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);

Loading…
Cancel
Save