Fixed session expiring and added logout page
This commit is contained in:
parent
3efa16fe0a
commit
a3d5f290a6
4 changed files with 32 additions and 5 deletions
|
@ -14,8 +14,10 @@
|
|||
</div>
|
||||
<div id="sidebar">
|
||||
<div id="userbox">
|
||||
Logged in as
|
||||
<username/>
|
||||
<p>Logged in as
|
||||
<username/>
|
||||
</p>
|
||||
<a href="/logout">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loginregisterbox">
|
||||
|
|
|
@ -120,8 +120,8 @@ public class IOHelper {
|
|||
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));
|
||||
exchange.getResponseHeaders().add("Set-Cookie",
|
||||
"session_id=" + user.getSessionid() + "; expires=" + expiretime);
|
||||
exchange.getResponseHeaders().add("Set-Cookie", "session_id=" + user.getSessionid() + "; expires="
|
||||
+ expiretime.format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
}
|
||||
|
||||
public static void LogoutUser(HttpExchange exchange, User user) {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class Main {
|
|||
provider.save(user2);
|
||||
User loggedinuser = new User();
|
||||
loggedinuser.setName("NorbiPeti");
|
||||
loggedinuser.setSessionid("8b148304-5dd6-48dd-a1a3-c8e47bcfc44b");
|
||||
loggedinuser.setSessionid("093b1395-8c31-4f3b-ba67-828a755af92e");
|
||||
loggedinuser.setEmail("sznp@asd.com");
|
||||
convo.getUsers().add(loggedinuser);
|
||||
loggedinuser.getConversations().add(convo);
|
||||
|
|
25
src/io/github/norbipeti/chat/server/page/LogoutPage.java
Normal file
25
src/io/github/norbipeti/chat/server/page/LogoutPage.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package io.github.norbipeti.chat.server.page;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
import io.github.norbipeti.chat.server.IOHelper;
|
||||
import io.github.norbipeti.chat.server.db.domain.User;
|
||||
|
||||
public class LogoutPage extends Page {
|
||||
|
||||
@Override
|
||||
public String GetName() {
|
||||
return "logout";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePage(HttpExchange exchange) throws IOException {
|
||||
User user = IOHelper.GetLoggedInUser(exchange);
|
||||
if (user != null)
|
||||
IOHelper.LogoutUser(exchange, user);
|
||||
IOHelper.Redirect("/", exchange);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue