30 lines
1.5 KiB
Java
30 lines
1.5 KiB
Java
package ru.redguy.webinfomod.pages;
|
|
|
|
import fi.iki.elonen.NanoHTTPD;
|
|
import org.apache.commons.io.IOUtils;
|
|
import ru.redguy.webinfomod.*;
|
|
import ru.redguy.webinfomod.langs.LangFile;
|
|
import ru.redguy.webinfomod.langs.enums.Links;
|
|
import ru.redguy.webinfomod.langs.enums.RootCategories;
|
|
import ru.redguy.webinfomod.utils.WebUtils;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
@WebPage(url = "/")
|
|
public class Index implements IWebPage {
|
|
public NanoHTTPD.Response getPage(Config config, LangFile langFile, NanoHTTPD.IHTTPSession session) throws IOException {
|
|
String path = "/resources/web/pages/Index.html";
|
|
String page = IOUtils.toString(WebServer.class.getResourceAsStream(path), StandardCharsets.UTF_8);
|
|
WebUtils.CookieHandler ch = new WebUtils.CookieHandler(session.getHeaders());
|
|
if(ch.read("session") == null) {
|
|
page = page.replace("<replace id=\"1\"/>","<a href=\"auth/\" class=\"authLink\">"+langFile.getCategory(RootCategories.Links).getString(Links.login)+"</a>");
|
|
} else {
|
|
page = page.replace("<replace id=\"1\"/>","<a href=\"logout/\" class=\"authLink\">"+langFile.getCategory(RootCategories.Links).getString(Links.logout)+"</a><br>" +
|
|
"<a href=\"cp\" class=\"authLink\">"+langFile.getCategory(RootCategories.Links).getString(Links.controlPanel)+"</a>");
|
|
}
|
|
return NanoHTTPD.newFixedLengthResponse(page);
|
|
}
|
|
}
|