Did getUser, started register
This commit is contained in:
parent
c07a0d6207
commit
ddbcc536a7
4 changed files with 46 additions and 11 deletions
|
@ -1,5 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<h1>Register</h1>
|
||||
<p>Hello</p>
|
||||
<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>
|
||||
|
|
|
@ -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,
|
||||
"<h1>501 Not Implemented</h1><p>The page \"" + page.GetName() + "\" cannot be found on disk.</h1>",
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -36,12 +36,12 @@ public class DataProvider implements AutoCloseable {
|
|||
return users;
|
||||
}
|
||||
|
||||
public List<User> getUser(Long id) { //TODO
|
||||
public User getUser(Long id) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
TypedQuery<User> query = em.createQuery("SELECT u FROM User u", User.class);
|
||||
List<User> users = query.getResultList();
|
||||
TypedQuery<User> 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) {
|
||||
|
|
Loading…
Reference in a new issue