diff --git a/src/db/jdcb.java b/src/db/jdcb.java index c32f6a5..40ca699 100644 --- a/src/db/jdcb.java +++ b/src/db/jdcb.java @@ -7,17 +7,9 @@ import java.sql.ResultSet; import java.sql.SQLException; public class jdcb { - String username; - String password; - String dbName; +Connection conn; public jdcb(String username, String password, String dbName) { - this.username = username; - this.password=password; - this.dbName = dbName; - } - - public ResultSet executeQuery(String sql) { Database db = new MySQLConnector( username, password, @@ -25,10 +17,14 @@ public class jdcb { 3306, dbName); - Connection c = db.getConnection(); + conn = db.getConnection(); + + } + + public ResultSet executeQuery(String sql) { + try { - PreparedStatement stmt = - c.prepareStatement(sql); + PreparedStatement stmt = conn.prepareStatement(sql); return stmt.executeQuery(); } catch (SQLException e) { @@ -36,4 +32,15 @@ public class jdcb { } return null; } + + public int executeUpdate(String sql){ + try { + PreparedStatement stmt = conn.prepareStatement(sql); + + return stmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + return -1; + } } diff --git a/src/website/RegisterRequest.java b/src/website/RegisterRequest.java new file mode 100644 index 0000000..3a23f15 --- /dev/null +++ b/src/website/RegisterRequest.java @@ -0,0 +1,20 @@ +package website; + +import db.jdcb; + +import java.util.HashMap; + +public class RegisterRequest extends PostRequest{ + @Override + public String request(HashMap params) { + System.out.println(params.toString()); + + String passhash = HttpTools.StringToMD5(params.get("password")); + + jdcb myjd = new jdcb("users", "kOpaIJUjkgb9ur6S", "wasteinformation"); + int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('"+params.get("username")+"', '"+params.get("firstname")+"', '"+params.get("lastname")+"', '"+passhash+"', '"+params.get("email")+"', current_timestamp());"); + + + return "{\"accept\": true}"; + } +} diff --git a/src/website/Webserver.java b/src/website/Webserver.java index 9055d62..9ba0ce9 100644 --- a/src/website/Webserver.java +++ b/src/website/Webserver.java @@ -18,6 +18,7 @@ public class Webserver { server.createContext("/", new MainPage()); server.createContext("/senddata/loginget", new LoginRequest()); + server.createContext("/senddata/registerpost",new RegisterRequest()); server.setExecutor(null); // creates a default executor server.start(); diff --git a/wwwroot/css/general.css b/wwwroot/css/general.css new file mode 100644 index 0000000..0efc4e5 --- /dev/null +++ b/wwwroot/css/general.css @@ -0,0 +1,3 @@ +.hideit{ + display:none; +} diff --git a/wwwroot/index.html b/wwwroot/index.html index 8e2f5a6..78ed2ba 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -57,7 +57,7 @@