e.printStackTrace();
}
}
private void userDetails(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
User user = null;
try {
user = Authenticate.getConnectedUser(request);
} catch (NumberFormatException | ParseException e) {
throw new ServletException(e);
}
if(user == null) {
throw new ServletException("Vous n'êtes pas/plus connecté");
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
JSONObject jsonUser = new JSONObject();
jsonUser.put("id", KeyFactory.keyToString(user.getKey()));
jsonUser.put("nom", user.getNom());
jsonUser.put("prenom", user.getPrenom());
jsonUser.put("dateNaissance", simpleDateFormat.format(user.getDateNaissance()));
jsonUser.put("email", user.getEmail());
jsonUser.put("login", user.getLogin());
jsonUser.put("dateCreation", simpleDateFormat.format(user.getDateCreation()));
if(user.getDateConnexion() != null) {
jsonUser.put("lastConnection", simpleDateFormat.format(user.getDateConnexion()));
}
jsonUser.put("duration", user.getDureeConnexion());
response.getWriter().print(jsonUser);
}