public Response login(@Valid User user, @Context HttpServletRequest request)
throws JOSEException {
Optional<User> foundUser = dao.findByEmail(user.getEmail());
if (foundUser.isPresent()
&& PasswordService.checkPassword(user.getPassword(), foundUser.get().getPassword())) {
Token token = AuthUtils.createToken(request.getRemoteHost(), foundUser.get().getId());
return Response.ok().entity(token).build();
}
return Response.status(Status.UNAUTHORIZED).entity(new ErrorMessage(LOGING_ERROR_MSG))
.build();
}