(Re)Added expire time for cookies (Just deleted today's work)
This commit is contained in:
parent
28c46a7401
commit
12be973724
4 changed files with 26 additions and 3 deletions
|
@ -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>
|
||||
|
|
2
.settings/org.eclipse.vjet.eclipse.core.prefs
Normal file
2
.settings/org.eclipse.vjet.eclipse.core.prefs
Normal file
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
initialized_project_from_v4classpath=true
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue