Add cp page

This commit is contained in:
Ilya 2020-11-25 22:05:57 +03:00
parent aea5600d8e
commit 41bb8be727
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package ru.redguy.webinfomod.pages.cp;
import fi.iki.elonen.NanoHTTPD;
import org.apache.commons.io.IOUtils;
import ru.redguy.webinfomod.Config;
import ru.redguy.webinfomod.IWebPage;
import ru.redguy.webinfomod.WebPage;
import ru.redguy.webinfomod.WebServer;
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.StandardCharsets;
@WebPage(url = "/cp/")
public class Index implements IWebPage {
public NanoHTTPD.Response getPage(Config config, LangFile langFile, NanoHTTPD.IHTTPSession session) throws IOException {
String path = "/resources/web/pages/cp/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);
}
}

View File

@ -0,0 +1,3 @@
.authLink {
float: right;
}

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>WebInfo</title>
<link rel="stylesheet" type="text/css" href="/css/index.css">
</head>
<body>
<div class="header" id="header">
Идёт загрузка...
</div>
<main>
<replace id="1"/>
</main>
</body>
</html>