Skip to content

Commit

Permalink
Use the same top nav bar on index.html and search results.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luccioman committed Oct 24, 2017
1 parent d8eaf62 commit d0bed78
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion htroot/index.html
Expand Up @@ -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>
Expand Down
50 changes: 47 additions & 3 deletions htroot/index.java
Expand Up @@ -52,9 +52,15 @@ public static serverObjects respond(final RequestHeader header, final serverObje
}

// 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;
}
Expand Down Expand Up @@ -136,9 +142,47 @@ public static serverObjects respond(final RequestHeader header, final serverObje
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);
}
}
}
3 changes: 1 addition & 2 deletions htroot/yacysearch.java
Expand Up @@ -109,8 +109,7 @@ public static serverObjects respond(

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);
Expand Down

0 comments on commit d0bed78

Please sign in to comment.