Registration and login are now done with JavaScript from index.html
This commit is contained in:
parent
0308228e4a
commit
6ee360df0b
11 changed files with 193 additions and 137 deletions
|
@ -2,10 +2,17 @@
|
|||
<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$/js/register.js" />
|
||||
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/js/utils.js" />
|
||||
<change type="DELETED" beforePath="$PROJECT_DIR$/register.html" afterPath="" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/css/style.css" afterPath="$PROJECT_DIR$/css/style.css" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.html" afterPath="$PROJECT_DIR$/index.html" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/js/login.js" afterPath="$PROJECT_DIR$/js/login.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/DataProvider.java" afterPath="$PROJECT_DIR$/../src/io/github/norbipeti/chat/server/db/DataProvider.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" />
|
||||
<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" />
|
||||
</list>
|
||||
<ignored path="pages.iws" />
|
||||
<ignored path=".idea/workspace.xml" />
|
||||
|
@ -29,8 +36,8 @@
|
|||
<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="238">
|
||||
<caret line="14" column="19" selection-start-line="14" selection-start-column="19" selection-end-line="14" selection-end-column="19" />
|
||||
<state relative-caret-position="193">
|
||||
<caret line="48" column="20" selection-start-line="48" selection-start-column="20" selection-end-line="48" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -41,18 +48,28 @@
|
|||
<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>
|
||||
</file>
|
||||
<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="187">
|
||||
<caret line="13" column="38" selection-start-line="13" selection-start-column="38" selection-end-line="13" selection-end-column="38" />
|
||||
<folding>
|
||||
<marker date="1469189245325" expanded="true" signature="26510:26515" placeholder="..." />
|
||||
<element signature="n#!!doc;n#login#0" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="login.js" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/js/login.js">
|
||||
<file leaf-file-name="utils.js" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/js/utils.js">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="306">
|
||||
<caret line="20" column="44" selection-start-line="20" selection-start-column="44" selection-end-line="20" selection-end-column="44" />
|
||||
<state relative-caret-position="187">
|
||||
<caret line="13" column="0" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" />
|
||||
<folding>
|
||||
<element signature="n#!!doc;n#getFormData#0" expanded="false" />
|
||||
</folding>
|
||||
|
@ -70,12 +87,14 @@
|
|||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="register.html" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/register.html">
|
||||
<file leaf-file-name="register.js" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/js/register.js">
|
||||
<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 relative-caret-position="255">
|
||||
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
|
||||
<folding>
|
||||
<element signature="n#!!doc;n#register#0" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -120,7 +139,10 @@
|
|||
<option value="$PROJECT_DIR$/js/userbox.js" />
|
||||
<option value="$PROJECT_DIR$/js/message.js" />
|
||||
<option value="$PROJECT_DIR$/css/style.css" />
|
||||
<option value="$PROJECT_DIR$/register.html" />
|
||||
<option value="$PROJECT_DIR$/js/utils.js" />
|
||||
<option value="$PROJECT_DIR$/index.html" />
|
||||
<option value="$PROJECT_DIR$/js/register.js" />
|
||||
<option value="$PROJECT_DIR$/js/login.js" />
|
||||
</list>
|
||||
</option>
|
||||
|
@ -236,7 +258,7 @@
|
|||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="HbShouldOpenHtmlAsHb" value="" />
|
||||
<property name="settings.editor.selected.configurable" value="vcs.Git" />
|
||||
<property name="settings.editor.selected.configurable" value="fileTemplates" />
|
||||
<property name="settings.editor.splitter.proportion" value="0.2" />
|
||||
<property name="FileHistory.git4idea.history.GitHistoryProvider_flatWidth0" value="72" />
|
||||
<property name="FileHistory.git4idea.history.GitHistoryProvider_flatOrder0" value="0" />
|
||||
|
@ -347,12 +369,12 @@
|
|||
<updated>1469522327377</updated>
|
||||
<workItem from="1469522328775" duration="6392000" />
|
||||
<workItem from="1469535953166" duration="2597000" />
|
||||
<workItem from="1469602650261" duration="4137000" />
|
||||
<workItem from="1469602650261" duration="7736000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="13126000" />
|
||||
<option name="totallyTimeSpent" value="16725000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
|
||||
|
@ -360,8 +382,8 @@
|
|||
<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" />
|
||||
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32911393" sideWeight="0.50208336" order="0" side_tool="true" content_ui="tabs" />
|
||||
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32911393" sideWeight="0.49791667" order="4" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32911393" sideWeight="0.50416666" order="0" side_tool="true" content_ui="tabs" />
|
||||
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32911393" sideWeight="0.49583334" order="4" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32911393" sideWeight="0.49583334" order="1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" 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="5" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Structure" active="false" anchor="left" 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="tabs" />
|
||||
|
@ -405,7 +427,7 @@
|
|||
<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#getFormData#0" expanded="false" />
|
||||
<element signature="n#!!doc;n#login#0" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -467,7 +489,9 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/notfound.html">
|
||||
<entry file="file://$PROJECT_DIR$/userbox.html" />
|
||||
<entry file="file://$PROJECT_DIR$/js/userbox.js" />
|
||||
<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" />
|
||||
|
@ -475,16 +499,6 @@
|
|||
</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">
|
||||
<caret line="16" column="55" selection-start-line="16" selection-start-column="55" selection-end-line="16" selection-end-column="55" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/js/userbox.js" />
|
||||
<entry file="file://$PROJECT_DIR$/js/message.js">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="68">
|
||||
|
@ -493,6 +507,14 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/register.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="68">
|
||||
<caret line="4" column="27" selection-start-line="4" selection-start-column="27" selection-end-line="4" selection-end-column="27" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/css/style.css">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="17">
|
||||
|
@ -501,33 +523,51 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/js/jquery-3.1.0.js">
|
||||
<entry file="file://$PROJECT_DIR$/js/utils.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>
|
||||
<marker date="1469189245325" expanded="true" signature="26510:26515" placeholder="..." />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="238">
|
||||
<caret line="14" column="19" selection-start-line="14" selection-start-column="19" selection-end-line="14" selection-end-column="19" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/js/login.js">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="306">
|
||||
<caret line="20" column="44" selection-start-line="20" selection-start-column="44" selection-end-line="20" selection-end-column="44" />
|
||||
<state relative-caret-position="187">
|
||||
<caret line="13" column="0" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" />
|
||||
<folding>
|
||||
<element signature="n#!!doc;n#getFormData#0" expanded="false" />
|
||||
</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$/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="193">
|
||||
<caret line="48" column="20" selection-start-line="48" selection-start-column="20" selection-end-line="48" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/js/login.js">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="187">
|
||||
<caret line="13" column="38" selection-start-line="13" selection-start-column="38" selection-end-line="13" selection-end-column="38" />
|
||||
<folding>
|
||||
<element signature="n#!!doc;n#login#0" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/js/register.js">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="255">
|
||||
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
|
||||
<folding>
|
||||
<element signature="n#!!doc;n#register#0" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
|
@ -2,8 +2,10 @@
|
|||
<head>
|
||||
<title>ChatServer</title>
|
||||
<script src="js/jquery-3.1.0.js"></script>
|
||||
<script src="js/utils.js"></script>
|
||||
<script src="js/message.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
<script src="js/register.js"></script>
|
||||
<link rel="stylesheet" href="css/style.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -15,10 +17,57 @@
|
|||
<div id="errormsg">
|
||||
</div>
|
||||
<div id="loginbox">
|
||||
<form action="login" method="POST">
|
||||
E-mail: <input type="email" name="email">
|
||||
Password: <input type="password" name="pass">
|
||||
<input type="button" value="Login" onclick="check(this.form)">
|
||||
<form>
|
||||
<table>
|
||||
<tr>
|
||||
<td>E-mail:</td>
|
||||
<td>
|
||||
<input type="email" name="email">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password:</td>
|
||||
<td>
|
||||
<input type="password" name="pass">
|
||||
</td>
|
||||
</tr>
|
||||
<input type="button" value="Login" onclick="login(this.form)">
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div id="registerbox">
|
||||
<form>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Name:</td>
|
||||
<td>
|
||||
<input type="text" name="name"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>E-mail:</td>
|
||||
<td>
|
||||
<input type="email" name="email"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password</td>
|
||||
<td>
|
||||
<input type="password" name="pass"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password confirm</td>
|
||||
<td>
|
||||
<input type="password" name="pass2"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="button" value="Register" onclick="register(this.form)"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<input id="msginput" value=""/>
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
/**
|
||||
* Created by Norbert_Szatmari on 2016-07-26.
|
||||
* Created by Norbi on 2016-07-26.
|
||||
*/
|
||||
function getFormData($form) {
|
||||
var unindexed_array = $form.serializeArray();
|
||||
var indexed_array = {};
|
||||
|
||||
$.map(unindexed_array, function (n, i) {
|
||||
indexed_array[n['name']] = n['value'];
|
||||
});
|
||||
|
||||
return indexed_array;
|
||||
}
|
||||
|
||||
function check(form) {
|
||||
function login(form) {
|
||||
var json = JSON.stringify(getFormData($(form)));
|
||||
$.ajax({
|
||||
url: "/login", data: json, method: "POST", success: function (result) {
|
||||
|
@ -21,6 +10,8 @@ function check(form) {
|
|||
errormsg.innerHTML = result;
|
||||
errormsg.style = "display: block";
|
||||
}
|
||||
else
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
17
pages/js/register.js
Normal file
17
pages/js/register.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Created by Norbi on 2016-07-27.
|
||||
*/
|
||||
function register(form) {
|
||||
var json = JSON.stringify(getFormData($(form)));
|
||||
$.ajax({
|
||||
url: "/register", data: json, method: "POST", success: function (result) {
|
||||
if (result != "Success") {
|
||||
var errormsg = document.getElementById("errormsg");
|
||||
errormsg.innerHTML = result;
|
||||
errormsg.style = "display: block";
|
||||
}
|
||||
else
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
}
|
13
pages/js/utils.js
Normal file
13
pages/js/utils.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Created by Norbi on 2016-07-27.
|
||||
*/
|
||||
function getFormData($form) {
|
||||
var unindexed_array = $form.serializeArray();
|
||||
var indexed_array = {};
|
||||
|
||||
$.map(unindexed_array, function (n, i) {
|
||||
indexed_array[n['name']] = n['value'];
|
||||
});
|
||||
|
||||
return indexed_array;
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<h1>Register</h1>
|
||||
<div id="errormsg"></div>
|
||||
<div id="successmsg"></div>
|
||||
<table>
|
||||
<form action="register" method="POST">
|
||||
<tr>
|
||||
<td>Name:</td>
|
||||
<td>
|
||||
<input type="text" name="name" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>E-mail:</td>
|
||||
<td>
|
||||
<input type="email" name="email" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password</td>
|
||||
<td>
|
||||
<input type="password" name="pass" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password confirm</td>
|
||||
<td>
|
||||
<input type="password" name="pass2" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="submit" value="Register" />
|
||||
</td>
|
||||
</tr>
|
||||
</form>
|
||||
</table>
|
||||
</html>
|
|
@ -10,8 +10,6 @@ import java.time.ZoneId;
|
|||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -56,6 +54,7 @@ public class IOHelper {
|
|||
return content;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static HashMap<String, String> GetPOST(HttpExchange exchange) throws IOException {
|
||||
if (exchange.getRequestBody().available() == 0)
|
||||
return new HashMap<>();
|
||||
|
@ -81,7 +80,6 @@ public class IOHelper {
|
|||
return null;
|
||||
try {
|
||||
String content = IOUtils.toString(exchange.getRequestBody(), StandardCharsets.ISO_8859_1);
|
||||
HashMap<String, String> vars = new HashMap<>();
|
||||
JSONObject obj = new JSONObject(content);
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -7,10 +7,8 @@ import java.util.Set;
|
|||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
|
@ -18,8 +16,6 @@ import org.reflections.util.ClasspathHelper;
|
|||
import org.reflections.util.ConfigurationBuilder;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.org.apache.xerces.internal.parsers.BasicParserConfiguration;
|
||||
|
||||
import io.github.norbipeti.chat.server.db.*;
|
||||
import io.github.norbipeti.chat.server.db.domain.*;
|
||||
import io.github.norbipeti.chat.server.page.*;
|
||||
|
@ -36,7 +32,7 @@ public class Main {
|
|||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
Configuration config = ctx.getConfiguration();
|
||||
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
|
||||
loggerConfig.setLevel(Level.DEBUG);
|
||||
loggerConfig.setLevel(Level.WARN);
|
||||
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
|
||||
System.out.println("Loading database...");
|
||||
try (DataProvider provider = new DataProvider()) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package io.github.norbipeti.chat.server.db;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package io.github.norbipeti.chat.server.page;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
@ -33,13 +30,12 @@ public class LoginPage extends Page {
|
|||
if (loginuser == null || !BCrypt.checkpw(post.getString("pass"), loginuser.getPassword())) {
|
||||
IOHelper.SendResponse(200, (doc) -> {
|
||||
doc.appendElement("p").text("The username or password is invalid.");
|
||||
doc.attr("style", "display: block");
|
||||
return doc;
|
||||
}, exchange);
|
||||
return;
|
||||
}
|
||||
IOHelper.LoginUser(exchange, loginuser, provider);
|
||||
IOHelper.Redirect("/", exchange);
|
||||
IOHelper.SendResponse(200, "Success", exchange);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package io.github.norbipeti.chat.server.page;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
@ -14,13 +13,12 @@ import io.github.norbipeti.chat.server.db.domain.User;
|
|||
public class RegisterPage extends Page {
|
||||
@Override
|
||||
public void handlePage(HttpExchange exchange) throws IOException {
|
||||
HashMap<String, String> post = IOHelper.GetPOST(exchange);
|
||||
if (post.size() > 0) {
|
||||
JSONObject post = IOHelper.GetPOSTJSON(exchange);
|
||||
if (post != null) {
|
||||
String errormsg = CheckValues(post, "name", "email", "pass", "pass2");
|
||||
if (errormsg.length() > 0) {
|
||||
final String msg = errormsg;
|
||||
IOHelper.SendModifiedPage(200, this, (doc) -> doc.getElementById("errormsg").text(msg).ownerDocument(),
|
||||
exchange);
|
||||
IOHelper.SendResponse(200, (doc) -> doc.html(msg).ownerDocument(), exchange);
|
||||
return; // TODO: Use JavaScript too, for error checks
|
||||
}
|
||||
try (DataProvider provider = new DataProvider()) {
|
||||
|
@ -34,31 +32,30 @@ public class RegisterPage extends Page {
|
|||
errormsg += "<p>The passwords don't match</p>";
|
||||
if (errormsg.length() > 0) {
|
||||
final String msg = errormsg;
|
||||
IOHelper.SendModifiedPage(200, this,
|
||||
(doc) -> doc.getElementById("errormsg").text(msg).ownerDocument(), exchange);
|
||||
IOHelper.SendResponse(200, (doc) -> doc.html(msg).ownerDocument(), exchange);
|
||||
return;
|
||||
}
|
||||
User user = new User();
|
||||
user.setName(post.get("name"));
|
||||
user.setEmail(post.get("email"));
|
||||
user.setName(post.getString("name"));
|
||||
user.setEmail(post.getString("email"));
|
||||
user.setSalt(BCrypt.gensalt()); // http://www.mindrot.org/projects/jBCrypt/
|
||||
user.setPassword(BCrypt.hashpw(post.get("pass"), user.getSalt()));
|
||||
user.setPassword(BCrypt.hashpw(post.getString("pass"), user.getSalt()));
|
||||
provider.addUser(user);
|
||||
User managedUser = provider.getUser(user.getId());
|
||||
IOHelper.LoginUser(exchange, managedUser, provider);
|
||||
IOHelper.Redirect("/", exchange);
|
||||
IOHelper.SendResponse(200, "Success", exchange);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
return;
|
||||
}
|
||||
IOHelper.SendPage(200, this, exchange);
|
||||
IOHelper.Redirect("/", exchange);
|
||||
}
|
||||
|
||||
private String CheckValues(HashMap<String, String> post, String... values) {
|
||||
private String CheckValues(JSONObject post, String... values) {
|
||||
String errormsg = "";
|
||||
for (String value : values)
|
||||
if (!CheckValue(post.get(value)))
|
||||
if (!CheckValue(post.getString(value)))
|
||||
errormsg += "<p>" + value + " can't be empty</p>";
|
||||
return errormsg;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue