From ddbcc536a75eaf90ef13f003c94b66e6d680373f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 19 Jul 2016 14:07:54 +0200 Subject: [PATCH] Did getUser, started register --- pages/register.html | 34 ++++++++++++++++++- .../norbipeti/chat/server/IOHelper.java | 11 ++++-- src/io/github/norbipeti/chat/server/Main.java | 4 +-- .../chat/server/db/DataProvider.java | 8 ++--- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/pages/register.html b/pages/register.html index bb17637..198dc47 100644 --- a/pages/register.html +++ b/pages/register.html @@ -1,5 +1,37 @@

Register

-

Hello

+ + + + + + + + + + + + + + + + + + + + + + +
Name: + +
E-mail: + +
Password + +
Password confirm + +
+ +
diff --git a/src/io/github/norbipeti/chat/server/IOHelper.java b/src/io/github/norbipeti/chat/server/IOHelper.java index 83c46b2..282e92a 100644 --- a/src/io/github/norbipeti/chat/server/IOHelper.java +++ b/src/io/github/norbipeti/chat/server/IOHelper.java @@ -18,16 +18,21 @@ public class IOHelper { } public static boolean SendPage(int code, Page page, HttpExchange exchange) throws IOException { + String content = GetPage(page, exchange); + SendResponse(code, content, exchange); + return true; + } + + public static String GetPage(Page page, HttpExchange exchange) throws IOException { File file = new File(page.GetHTMLPath()); if (!file.exists()) { SendResponse(501, "

501 Not Implemented

The page \"" + page.GetName() + "\" cannot be found on disk.", exchange); - return false; + return null; } FileInputStream inputStream = new FileInputStream(file); String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8); - SendResponse(code, content, exchange); - return true; + return content; } } diff --git a/src/io/github/norbipeti/chat/server/Main.java b/src/io/github/norbipeti/chat/server/Main.java index 8c4a111..f7de172 100644 --- a/src/io/github/norbipeti/chat/server/Main.java +++ b/src/io/github/norbipeti/chat/server/Main.java @@ -5,9 +5,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Set; -import javax.persistence.EntityManager; - -import org.hibernate.Hibernate; import org.reflections.Reflections; import org.reflections.scanners.SubTypesScanner; import org.reflections.util.ClasspathHelper; @@ -36,6 +33,7 @@ public class Main { user2.getContacts().add(user.getId()); provider.addUser(user2); System.out.println(provider.getUsers()); + System.out.println("Contact: " + provider.getUser(user2.getContacts().get(0))); } System.out.println("Starting webserver..."); HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 8080), 10); diff --git a/src/io/github/norbipeti/chat/server/db/DataProvider.java b/src/io/github/norbipeti/chat/server/db/DataProvider.java index 4abbb38..63a617b 100644 --- a/src/io/github/norbipeti/chat/server/db/DataProvider.java +++ b/src/io/github/norbipeti/chat/server/db/DataProvider.java @@ -36,12 +36,12 @@ public class DataProvider implements AutoCloseable { return users; } - public List getUser(Long id) { //TODO + public User getUser(Long id) { EntityManager em = emf.createEntityManager(); - TypedQuery query = em.createQuery("SELECT u FROM User u", User.class); - List users = query.getResultList(); + TypedQuery query = em.createQuery("SELECT u FROM User u WHERE u.id = " + id, User.class); + User user = query.getResultList().get(0); em.close(); - return users; + return user; } public void removeUser(User user) {