Removed unnecessary sysouts and uncommented a code

This commit is contained in:
Norbi Peti 2016-07-28 11:36:34 +02:00
parent 72f0af6e9a
commit 5626f77b5d
3 changed files with 4 additions and 17 deletions

View file

@ -105,7 +105,6 @@ public class IOHelper {
// user.setSessionid(UUID.randomUUID().toString()));
user.setSessionid(UUID.randomUUID().toString());
provider.saveUser(user);
System.out.println("Session ID set to " + user.getSessionid());
ZonedDateTime expiretime = ZonedDateTime.now(ZoneId.of("GMT")).plus(Period.of(2, 0, 0));
exchange.getResponseHeaders().add("Set-Cookie",
"user_id=" + user.getId() + "; expires=" + expiretime.format(DateTimeFormatter.RFC_1123_DATE_TIME));
@ -154,16 +153,10 @@ public class IOHelper {
*/
public static User GetLoggedInUser(HttpExchange exchange) {
HashMap<String, String> cookies = GetCookies(exchange);
System.out.println("Cookies: " + cookies);
if (!cookies.containsKey("user_id") || !cookies.containsKey("session_id"))
return null;
System.out.println("Cookies found");
try (DataProvider provider = new DataProvider()) {
User user = provider.getUser(Long.parseLong(cookies.get("user_id")));
System.out.println("User: " + user);
System.out.println("session_id: " + cookies.get("session_id"));
if (user != null)
System.out.println("Equals: " + cookies.get("session_id").equals(user.getSessionid()));
if (user != null && cookies.get("session_id") != null
&& cookies.get("session_id").equals(user.getSessionid()))
return user;

View file

@ -30,14 +30,6 @@ public class Main {
try { // rt.jar Javadoc:
// https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/
// https://docs.oracle.com/javase/8/docs/api/
System.out.println(System.getProperty("java.class.path")); // TODO:
// log4j
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
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()) {
User user = new User();

View file

@ -7,6 +7,8 @@ import org.jsoup.nodes.Element;
import com.sun.net.httpserver.HttpExchange;
import io.github.norbipeti.chat.server.IOHelper;
import io.github.norbipeti.chat.server.db.DataProvider;
import io.github.norbipeti.chat.server.db.domain.Conversation;
import io.github.norbipeti.chat.server.db.domain.Message;
import io.github.norbipeti.chat.server.db.domain.User;
public class IndexPage extends Page {
@ -32,14 +34,14 @@ public class IndexPage extends Page {
userbox.html(userbox.html().replace("<username />", user.getName()));
Element channelmessages = doc.getElementById("channelmessages");
try (DataProvider provider = new DataProvider()) {
/*Conversation convo = provider.getConversations().get(0); // TODO
Conversation convo = provider.getConversations().get(0);
for (Message message : convo.getMesssages()) {
Element msgelement = channelmessages.appendElement("div");
Element header = msgelement.appendElement("p");
header.text(message.getSender().getName() + " - " + message.getTime());
Element body = msgelement.appendElement("p");
body.text(message.getMessage());
}*/
}
}
return doc;
}, exchange);