Added login things

This commit is contained in:
Norbi Peti 2016-07-26 15:10:18 +02:00
parent 36aaa9f80a
commit d619811a34
10 changed files with 125 additions and 57 deletions

View file

@ -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

View file

@ -2,17 +2,16 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="588ba1ca-220a-4913-8e8c-5657fa1c845f" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/../main/resources/META-INF/log4j.properties" />
<change type="MOVED" beforePath="$PROJECT_DIR$/../src/main/resources/META-INF/persistence.xml" afterPath="$PROJECT_DIR$/../main/resources/META-INF/persistence.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../.classpath" afterPath="$PROJECT_DIR$/../.classpath" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/css/style.css" afterPath="$PROJECT_DIR$/css/style.css" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/js/login.js" />
<change type="DELETED" beforePath="$PROJECT_DIR$/js/userbox.js" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/login.html" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../.settings/org.eclipse.jdt.core.prefs" afterPath="$PROJECT_DIR$/../.settings/org.eclipse.jdt.core.prefs" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.html" afterPath="$PROJECT_DIR$/index.html" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/login.html" afterPath="$PROJECT_DIR$/login.html" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../pom.xml" afterPath="$PROJECT_DIR$/../pom.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/js/message.js" afterPath="$PROJECT_DIR$/js/message.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/IOHelper.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/IOHelper.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/Main.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/Main.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/db/domain/User.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/db/domain/User.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/IndexPage.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/IndexPage.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/RegisterPage.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/RegisterPage.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/LoginPage.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/page/LoginPage.java" />
</list>
<ignored path="pages.iws" />
<ignored path=".idea/workspace.xml" />
@ -32,23 +31,25 @@
<favorites_list name="pages" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="index.html" pinned="false" current-in-tab="true">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="index.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="39" selection-start-line="15" selection-start-column="39" selection-end-line="15" selection-end-column="39" />
<caret line="15" column="59" selection-start-line="15" selection-start-column="59" selection-end-line="15" selection-end-column="59" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="userbox.js" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/userbox.js">
<file leaf-file-name="login.js" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/login.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="7" column="5" selection-start-line="7" selection-start-column="5" selection-end-line="7" selection-end-column="5" />
<folding />
<state relative-caret-position="34">
<caret line="4" column="26" selection-start-line="4" selection-start-column="26" selection-end-line="4" selection-end-column="26" />
<folding>
<element signature="n#!!doc;n#check#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
@ -73,7 +74,7 @@
</provider>
</entry>
</file>
<file leaf-file-name="message.js" pinned="false" current-in-tab="false">
<file leaf-file-name="message.js" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/js/message.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
@ -98,11 +99,12 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/js/message.js" />
<option value="$PROJECT_DIR$/userbox.js" />
<option value="$PROJECT_DIR$/userbox.html" />
<option value="$PROJECT_DIR$/js/userbox.js" />
<option value="$PROJECT_DIR$/js/message.js" />
<option value="$PROJECT_DIR$/index.html" />
<option value="$PROJECT_DIR$/js/login.js" />
</list>
</option>
</component>
@ -161,6 +163,8 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="Scratches" />
<pane id="ProjectPane">
<subPane>
<PATH>
@ -195,8 +199,6 @@
</PATH>
</subPane>
</pane>
<pane id="Scope" />
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
@ -259,6 +261,12 @@
<method />
</configuration>
<configuration default="true" type="js.build_tools.gulp" factoryName="Gulp.js">
<node-interpreter>project</node-interpreter>
<node-options />
<gulpfile />
<tasks />
<arguments />
<envs />
<method />
</configuration>
<configuration default="true" type="js.build_tools.npm" factoryName="npm">
@ -296,6 +304,9 @@
<option name="remove_strategy" value="false" />
</component>
<component name="SpellCheckerSettings" BundledDictionaries="1" BundledDictionary0="english.dic" Folders="0" Dictionaries="0" />
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="588ba1ca-220a-4913-8e8c-5657fa1c845f" name="Default" comment="" />
@ -303,16 +314,17 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1469522327377</updated>
<workItem from="1469522328775" duration="6077000" />
<workItem from="1469522328775" duration="6392000" />
<workItem from="1469535953166" duration="2597000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="6077000" />
<option name="totallyTimeSpent" value="8989000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<editor active="false" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.18020834" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
@ -325,10 +337,10 @@
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
@ -348,21 +360,26 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/js/jquery-3.1.0.js">
<entry file="file://$PROJECT_DIR$/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="n#!!doc" expanded="true" />
<marker date="1469189245325" expanded="true" signature="26510:26515" placeholder="..." />
</folding>
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/message.js">
<entry file="file://$PROJECT_DIR$/js/userbox.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="4" column="0" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
<state relative-caret-position="119">
<caret line="7" column="5" selection-start-line="7" selection-start-column="5" selection-end-line="7" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/register.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="55" selection-start-line="16" selection-start-column="55" selection-end-line="16" selection-end-column="55" />
<folding />
</state>
</provider>
@ -375,14 +392,34 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/userbox.html">
<entry file="file://$PROJECT_DIR$/js/message.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="20" selection-start-line="1" selection-start-column="20" selection-end-line="1" selection-end-column="20" />
<state relative-caret-position="68">
<caret line="4" column="0" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/jquery-3.1.0.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="n#!!doc" expanded="true" />
<marker date="1469189245325" expanded="true" signature="26510:26515" placeholder="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/notfound.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/userbox.html" />
<entry file="file://$PROJECT_DIR$/register.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
@ -402,7 +439,25 @@
<entry file="file://$PROJECT_DIR$/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="39" selection-start-line="15" selection-start-column="39" selection-end-line="15" selection-end-column="39" />
<caret line="15" column="59" selection-start-line="15" selection-start-column="59" selection-end-line="15" selection-end-column="59" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/login.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="4" column="26" selection-start-line="4" selection-start-column="26" selection-end-line="4" selection-end-column="26" />
<folding>
<element signature="n#!!doc;n#check#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/message.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="4" column="0" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
<folding />
</state>
</provider>

View file

@ -3,17 +3,21 @@
<title>ChatServer</title>
<script src="js/jquery-3.1.0.js"></script>
<script src="js/message.js"></script>
<script src="js/login.js"></script>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<h1>Index</h1>
<div id="userbox">
Logged in as <username />
Logged in as
<username/>
</div>
<div id="loginbox">
E-mail: <input type=="email" name="email">
Password: <input type="password" name="pass">
<input type="submit" value="Login">
<form action="login" method="POST" onsubmit="check(this)">
E-mail: <input type="email" name="email">
Password: <input type="password" name="pass">
<input type="submit" value="Login">
</form>
</div>
<input id="msginput" value=""/>
</body>

3
pages/js/login.js Normal file
View file

@ -0,0 +1,3 @@
/**
* Created by Norbert_Szatmari on 2016-07-26.
*/

View file

@ -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);
});

View file

@ -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");
}
});

View file

@ -1 +0,0 @@
<div id="errormsg"></div>

View file

@ -155,4 +155,11 @@ public class IOHelper {
}
return null;
}
public static void SendResponse(int code, Page page, Function<Document, Document> action, HttpExchange exchange)
throws IOException {
Document doc = new Document("");
doc = action.apply(doc);
SendResponse(200, doc.html(), exchange);
}
}

View file

@ -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);

View file

@ -18,7 +18,7 @@ public class LoginPage extends Page {
public void handlePage(HttpExchange exchange) throws IOException {
HashMap<String, String> 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);