diff --git a/pages/register.html b/pages/register.html index 198dc47..1890d36 100644 --- a/pages/register.html +++ b/pages/register.html @@ -1,6 +1,12 @@

Register

+
+ +
+
+ +
diff --git a/src/io/github/norbipeti/chat/server/IOHelper.java b/src/io/github/norbipeti/chat/server/IOHelper.java index 7101000..dd0a356 100644 --- a/src/io/github/norbipeti/chat/server/IOHelper.java +++ b/src/io/github/norbipeti/chat/server/IOHelper.java @@ -44,17 +44,23 @@ public class IOHelper { } public static HashMap GetPOST(HttpExchange exchange) throws IOException { - System.out.println(exchange.getRequestBody().available()); if (exchange.getRequestBody().available() == 0) return new HashMap<>(); - String[] content = IOUtils.toString(exchange.getRequestBody(), StandardCharsets.ISO_8859_1).split("\\&"); - System.out.println(content); - HashMap vars = new HashMap<>(); - for (String var : content) { - String[] spl = var.split("\\="); - vars.put(spl[0], spl[1]); + try { + String[] content = IOUtils.toString(exchange.getRequestBody(), StandardCharsets.ISO_8859_1).split("\\&"); + HashMap vars = new HashMap<>(); + for (String var : content) { + String[] spl = var.split("\\="); + if (spl.length == 1) + vars.put(spl[0], ""); + else + vars.put(spl[0], spl[1]); + } + return vars; + } catch (Exception e) { + e.printStackTrace(); + return new HashMap<>(); } - return vars; } public static boolean SendModifiedPage(int code, Page page, String replace, String with, HttpExchange exchange) diff --git a/src/io/github/norbipeti/chat/server/db/domain/Conversation.java b/src/io/github/norbipeti/chat/server/db/domain/Conversation.java index d41fd24..5e66106 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/Conversation.java +++ b/src/io/github/norbipeti/chat/server/db/domain/Conversation.java @@ -2,11 +2,19 @@ package io.github.norbipeti.chat.server.db.domain; import java.util.List; -import javax.persistence.Entity; +import javax.persistence.*; @Entity public class Conversation { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true, nullable = false) + private Long id; + @ElementCollection + @OneToMany private List messsages; + @ElementCollection + @OneToMany private List users; public List getMesssages() { @@ -24,4 +32,12 @@ public class Conversation { public void setUsers(List users) { this.users = users; } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } } diff --git a/src/io/github/norbipeti/chat/server/db/domain/Message.java b/src/io/github/norbipeti/chat/server/db/domain/Message.java index 90ceea5..5a8d2a4 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/Message.java +++ b/src/io/github/norbipeti/chat/server/db/domain/Message.java @@ -2,13 +2,19 @@ package io.github.norbipeti.chat.server.db.domain; import java.util.Date; -import javax.persistence.Entity; +import javax.persistence.*; @Entity public class Message { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true, nullable = false) + private Long id; + @ManyToOne private User sender; private Date time; private String message; + @ManyToOne private Conversation conversation; public User getSender() { @@ -42,4 +48,12 @@ public class Message { public void setConversation(Conversation conversation) { this.conversation = conversation; } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } } diff --git a/src/io/github/norbipeti/chat/server/page/RegisterPage.java b/src/io/github/norbipeti/chat/server/page/RegisterPage.java index f576d3d..c5af0da 100644 --- a/src/io/github/norbipeti/chat/server/page/RegisterPage.java +++ b/src/io/github/norbipeti/chat/server/page/RegisterPage.java @@ -10,15 +10,13 @@ public class RegisterPage extends Page { @Override public void handlePage(HttpExchange exchange) throws IOException { HashMap post = IOHelper.GetPOST(exchange); - System.out.println("POST: " + post); if (post.size() > 0) { String errormsg = CheckValues(post, "name", "email", "pass", "pass2"); - System.out.println(errormsg); if (errormsg.length() == 0) { // Process register String successmsg = ""; IOHelper.SendModifiedPage(200, this, "", successmsg, exchange); - return; + return; // TODO: Only show tag when needed } else IOHelper.SendModifiedPage(200, this, "", errormsg, exchange); return;