From a55523951460478ededb73cf1b085858da5f013f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 7 Aug 2022 17:38:36 +0200 Subject: [PATCH] add connected_at --- src/main/java/com/covas/Entity/UsersEntity.java | 2 ++ src/main/java/com/covas/Resources/TokenRessource.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 4d707d5..ef8d610 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -49,6 +49,8 @@ public class UsersEntity extends PanacheEntityBase { public LocalDateTime updated_at; @ColumnDefault("null") public LocalDateTime deleted_at; + @ColumnDefault("null") + public LocalDateTime connected_at; public static UsersEntity findByPseudo(String pseudo){ return find("pseudo", pseudo).firstResult(); diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index b77b216..1b2bd20 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -2,6 +2,7 @@ package com.covas.Resources; import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.time.LocalDateTime; import javax.inject.Inject; import javax.ws.rs.CookieParam; @@ -71,6 +72,8 @@ public class TokenRessource { // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8)); + users.connected_at = LocalDateTime.now(); + users.persist(); return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", expires, false), new NewCookie(new Cookie("user", nameEncoded), "Username", expires, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized.