From d619811a34c60e4cf2afa9a50738a9b408f9e334 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 26 Jul 2016 15:10:18 +0200 Subject: [PATCH] Added login things --- .settings/org.eclipse.jdt.core.prefs | 8 ++ pages/.idea/workspace.xml | 129 +++++++++++++----- pages/index.html | 12 +- pages/js/login.js | 3 + pages/js/message.js | 2 +- pages/js/userbox.js | 9 -- pages/login.html | 1 - .../norbipeti/chat/server/IOHelper.java | 7 + src/io/github/norbipeti/chat/server/Main.java | 2 + .../norbipeti/chat/server/page/LoginPage.java | 9 +- 10 files changed, 125 insertions(+), 57 deletions(-) create mode 100644 pages/js/login.js delete mode 100644 pages/js/userbox.js delete mode 100644 pages/login.html diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 4d7db48..5648b30 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -8,9 +8,16 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -19,6 +26,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled diff --git a/pages/.idea/workspace.xml b/pages/.idea/workspace.xml index 9027532..80ddb89 100644 --- a/pages/.idea/workspace.xml +++ b/pages/.idea/workspace.xml @@ -2,17 +2,16 @@ - - - - + + + + + - - + + - - - + @@ -32,23 +31,25 @@ - - + + - + - - + + - - - + + + + + @@ -73,7 +74,7 @@ - + @@ -98,11 +99,12 @@ @@ -161,6 +163,8 @@ + + @@ -195,8 +199,6 @@ - - @@ -259,6 +261,12 @@ + project + + + + + @@ -296,6 +304,9 @@ + + + @@ -303,16 +314,17 @@ - - + @@ -325,10 +337,10 @@ - + @@ -348,21 +360,26 @@ - + - - - - + - + - - + + + + + + + + + + @@ -375,14 +392,34 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + @@ -402,7 +439,25 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/pages/index.html b/pages/index.html index d402b71..6b0113f 100644 --- a/pages/index.html +++ b/pages/index.html @@ -3,17 +3,21 @@ ChatServer +

Index

- Logged in as + Logged in as +
- E-mail: - Password: - +
+ E-mail: + Password: + +
diff --git a/pages/js/login.js b/pages/js/login.js new file mode 100644 index 0000000..746f451 --- /dev/null +++ b/pages/js/login.js @@ -0,0 +1,3 @@ +/** + * Created by Norbert_Szatmari on 2016-07-26. + */ diff --git a/pages/js/message.js b/pages/js/message.js index 69f3fb7..c8b69ef 100644 --- a/pages/js/message.js +++ b/pages/js/message.js @@ -1,4 +1,4 @@ -$(document).on("keypress", function(e) { +$('#msginput').keypress(function(e) { if (e.which == '\r'.charCodeAt(0)) document.write(document.getElementById("msginput").value); }); diff --git a/pages/js/userbox.js b/pages/js/userbox.js deleted file mode 100644 index 32f0127..0000000 --- a/pages/js/userbox.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Created by Norbi on 2016-07-26. - */ -$(document).ready(function () { - element = document.getElementById("userbox"); - if (element.offsetParent != null) { - $(element).load("userbox"); - } -}); \ No newline at end of file diff --git a/pages/login.html b/pages/login.html deleted file mode 100644 index ee5f4c6..0000000 --- a/pages/login.html +++ /dev/null @@ -1 +0,0 @@ -
diff --git a/src/io/github/norbipeti/chat/server/IOHelper.java b/src/io/github/norbipeti/chat/server/IOHelper.java index 1a383b9..02ded4e 100644 --- a/src/io/github/norbipeti/chat/server/IOHelper.java +++ b/src/io/github/norbipeti/chat/server/IOHelper.java @@ -155,4 +155,11 @@ public class IOHelper { } return null; } + + public static void SendResponse(int code, Page page, Function action, HttpExchange exchange) + throws IOException { + Document doc = new Document(""); + doc = action.apply(doc); + SendResponse(200, doc.html(), exchange); + } } diff --git a/src/io/github/norbipeti/chat/server/Main.java b/src/io/github/norbipeti/chat/server/Main.java index 96ed0be..7a7ef99 100644 --- a/src/io/github/norbipeti/chat/server/Main.java +++ b/src/io/github/norbipeti/chat/server/Main.java @@ -42,9 +42,11 @@ public class Main { try (DataProvider provider = new DataProvider()) { User user = new User(); user.setName("asd"); + user.setEmail("test@test.com"); provider.addUser(user); User user2 = new User(); user2.setName("Teszt"); + user2.setEmail("test2@test.com"); user2.getContacts().add(user); user.getContacts().add(user2); provider.addUser(user2); diff --git a/src/io/github/norbipeti/chat/server/page/LoginPage.java b/src/io/github/norbipeti/chat/server/page/LoginPage.java index 6145353..67cdcdd 100644 --- a/src/io/github/norbipeti/chat/server/page/LoginPage.java +++ b/src/io/github/norbipeti/chat/server/page/LoginPage.java @@ -18,7 +18,7 @@ public class LoginPage extends Page { public void handlePage(HttpExchange exchange) throws IOException { HashMap post = IOHelper.GetPOST(exchange); if (post.size() == 0 || !post.containsKey("email") || !post.containsKey("pass")) { - IOHelper.SendPage(200, this, exchange); + IOHelper.Redirect("/", exchange); return; } try (DataProvider provider = new DataProvider()) { @@ -30,10 +30,9 @@ public class LoginPage extends Page { } } if (loginuser == null || !BCrypt.checkpw(post.get("pass"), loginuser.getPassword())) { - IOHelper.SendModifiedPage(200, this, (doc) -> { - Element errorelement = doc.getElementById("errormsg"); - errorelement.appendElement("p").text("The username or password is invalid."); - errorelement.attr("style", "display: block"); + IOHelper.SendResponse(200, this, (doc) -> { + doc.appendElement("p").text("The username or password is invalid."); + doc.attr("style", "display: block"); return doc; // TODO: Automatically redirect on every // request, load HTML file directly for login }, exchange);