fix: changed login to use form params instead of json

This commit is contained in:
Laureηt 2022-05-27 16:16:45 +02:00
parent 434342bc86
commit 2f6ee4a742
No known key found for this signature in database
GPG key ID: D88C6B294FD40994

View file

@ -74,7 +74,9 @@ public class UserService {
@POST
@Path("signup")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void signup(@CookieParam("JSESSIONID") Cookie cookie, @FormParam("username") String username, @FormParam("password") String password) {
public void signup(@CookieParam("JSESSIONID") Cookie cookie, @FormParam("username") String username,
@FormParam("password") String password) {
// on créé un utilisateur
User new_user = new User(username, password);
@ -89,8 +91,10 @@ public class UserService {
@POST
@Path("login")
@Consumes(MediaType.APPLICATION_JSON)
public void login(@CookieParam("JSESSIONID") Cookie cookie, String json) {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void login(@CookieParam("JSESSIONID") Cookie cookie, @FormParam("username") String username,
@FormParam("password") String password) {
User user;
try {
// si on trouve l'utilisateur via son sessionID
@ -99,14 +103,11 @@ public class UserService {
LOGGER.info(user.getUsername() + " already logged in");
// TODO: renvoyer un json avec les creds
} catch (NoResultException e) {
// on parse le json en objet User
User json_user = gson.fromJson(json, User.class);
// on trouve le user à partir de son username
user = em.find(User.class, json_user.getUsername());
user = em.find(User.class, username);
// si les identifiants sont valides
if (user.validPassword(json_user.getPassword())) {
if (user.validPassword(password)) {
// on enregistre son sessionID
user.setSessionID(cookie.getValue());