Guest guest = AuthHelper.getGuest();
if (currentPassword!=null) {
boolean passwordMatched = guestService.checkPassword(guest.getId(), currentPassword);
if (!passwordMatched) {
return Response.ok(gson.toJson(new StatusModel(false, "Wrong Password"))).build();
}
}
if (password1.length()==0 || password2.length()==0)
return Response.ok(gson.toJson(new StatusModel(false, "Please fill in both password fields"))).build();
else {
if (!password1.equals(password2)) {
return Response.ok(gson.toJson(new StatusModel(false, "Passwords don't match"))).build();
}
if (password1.length()<8) {
return Response.ok(gson.toJson(new StatusModel(false, "Your password should be at least 8 characters long"))).build();
} else {
guestService.setPassword(guest.getId(), password1);
}
}
return Response.ok(new StatusModel(true, "settings updated!")).build();
}
catch (Exception e){
return Response.serverError().entity("Failed to save settings: " + e.getMessage()).build();
}
}