package net.pterodactylus.demoscenemusic.page;
import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.demoscenemusic.data.User;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateContextFactory;
@Override
protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException {
super.processTemplate(templateContext, request);
- templateContext.set("currentUser", request.getServletRequest().getSession().getAttribute("currentUser"));
+ User currentUser = (User) request.getServletRequest().getSession().getAttribute("currentUser");
+ templateContext.set("currentUser", currentUser);
+ int requiredUserLevel = getRequiredUserLevel();
+ if (((currentUser == null) && (requiredUserLevel > 0)) || ((currentUser != null) && (requiredUserLevel > currentUser.getLevel()))) {
+ throw new RedirectException("login");
+ }
+ }
+
+ /**
+ * Returns the {@link User#getLevel() user level} that is at least required
+ * to access the given page. If the returned level is {@code 0} (or
+ * smaller), users don’t have to be logged in.
+ *
+ * @return The lowest user level required to view this page
+ */
+ protected int getRequiredUserLevel() {
+ return 0;
}
}