(Re)Added expire time for cookies (Just deleted today's work)

This commit is contained in:
Norbi Peti 2016-07-22 14:17:21 +02:00
parent 28c46a7401
commit 12be973724
4 changed files with 26 additions and 3 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path="src"/>
<buildpathentry kind="con" path="org.eclipse.dltk.mod.launching.INTERPRETER_CONTAINER"/>
<buildpathentry kind="con" path="org.eclipse.vjet.eclipse.core.JSNATIVE_CONTAINER/JS Native Types"/>
<buildpathentry kind="con" path="org.eclipse.vjet.eclipse.core.BROWSER_CONTAINER/Browser SDK"/>
<buildpathentry kind="con" path="org.eclipse.vjet.eclipse.core.JSNATIVE_CONTAINER/JS Native Types"/>
<buildpathentry kind="con" path="org.eclipse.dltk.mod.launching.INTERPRETER_CONTAINER"/>
<buildpathentry kind="src" path="src"/>
</buildpath>

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
initialized_project_from_v4classpath=true

View file

@ -5,6 +5,9 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@ -75,6 +78,14 @@ public class IOHelper {
}
public static void LoginUser(HttpExchange exchange, User user) {
user.setSessionid(UUID.randomUUID());
ZonedDateTime expiretime = ZonedDateTime.now(ZoneId.of("GMT")).plus(Period.of(2, 0, 0));
exchange.getResponseHeaders().add("Set-Cookie", "user_id=" + user.getId() + "; expires=" + expiretime);
exchange.getResponseHeaders().add("Set-Cookie",
"session_id=" + user.getSessionid() + "; expires=" + expiretime);
}
public static void LogoutUser(HttpExchange exchange, User user) {
exchange.getResponseHeaders().add("Set-Cookie", "user_id=" + user.getId());
exchange.getResponseHeaders().add("Set-Cookie", "session_id=" + UUID.randomUUID());
}

View file

@ -2,6 +2,7 @@ package io.github.norbipeti.chat.server.db.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.persistence.*;
@ -18,6 +19,7 @@ public class User {
@ElementCollection(fetch = FetchType.EAGER)
private List<User> contacts;
private String salt;
private UUID sessionid;
public List<User> getContacts() {
if (contacts == null)
@ -78,6 +80,14 @@ public class User {
this.salt = salt;
}
public UUID getSessionid() {
return sessionid;
}
public void setSessionid(UUID sessionid) {
this.sessionid = sessionid;
}
public User() {
}