From 41bb8be727b30dc41e776d91ad16fef7688b531d Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 25 Nov 2020 22:05:57 +0300 Subject: [PATCH] Add cp page --- .../ru/redguy/webinfomod/pages/cp/Index.java | 31 +++++++++++++++++++ .../resources/resources/web/css/index.css | 3 ++ .../resources/web/pages/cp/index.html | 16 ++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/main/java/ru/redguy/webinfomod/pages/cp/Index.java create mode 100644 src/main/resources/resources/web/pages/cp/index.html diff --git a/src/main/java/ru/redguy/webinfomod/pages/cp/Index.java b/src/main/java/ru/redguy/webinfomod/pages/cp/Index.java new file mode 100644 index 0000000..0c29025 --- /dev/null +++ b/src/main/java/ru/redguy/webinfomod/pages/cp/Index.java @@ -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("",""+langFile.getCategory(RootCategories.Links).getString(Links.login)+""); + } else { + page = page.replace("",""+langFile.getCategory(RootCategories.Links).getString(Links.logout)+"
" + + ""+langFile.getCategory(RootCategories.Links).getString(Links.controlPanel)+""); + } + return NanoHTTPD.newFixedLengthResponse(page); + } +} diff --git a/src/main/resources/resources/web/css/index.css b/src/main/resources/resources/web/css/index.css index e69de29..5d2e8e8 100644 --- a/src/main/resources/resources/web/css/index.css +++ b/src/main/resources/resources/web/css/index.css @@ -0,0 +1,3 @@ +.authLink { + float: right; +} \ No newline at end of file diff --git a/src/main/resources/resources/web/pages/cp/index.html b/src/main/resources/resources/web/pages/cp/index.html new file mode 100644 index 0000000..c0d6750 --- /dev/null +++ b/src/main/resources/resources/web/pages/cp/index.html @@ -0,0 +1,16 @@ + + + + + WebInfo + + + + +
+ +
+ +