Commit 92c99e64 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

return not acceptable response on bad flag

parent 8ede0bff
...@@ -91,21 +91,15 @@ public class TasksRepository implements Repository { ...@@ -91,21 +91,15 @@ public class TasksRepository implements Repository {
} }
} }
private boolean compareHash(String hash, String username) throws Exception { public boolean checkFlag(String username, String flagValue) throws Exception {
Task task = getUserFlagsHashes(username).get(hash); Task task = getUserFlagsHashes(username).get(flagValue);
if(task != null) {
if (task != null) {
acceptSolution(username, task); acceptSolution(username, task);
return true; return true;
} }
return false; return false;
} }
public boolean checkFlag(String username, String flagValue) throws Exception {
return compareHash(flagValue, username);
//todo: accept solution should be here
}
public Optional<String> getUserTaskFlag(String username, String taskId) { public Optional<String> getUserTaskFlag(String username, String taskId) {
//todo: taskId, level, name? discuss //todo: taskId, level, name? discuss
return getUserFlagsHashes(username).entrySet().stream() return getUserFlagsHashes(username).entrySet().stream()
......
...@@ -63,9 +63,12 @@ public class TasksResource ...@@ -63,9 +63,12 @@ public class TasksResource
//todo: move to solutions resource //todo: move to solutions resource
@POST @POST
public boolean submitSolution(@Auth User user, public Response submitSolution(@Auth User user,
String flag) throws Exception { String flag) throws Exception {
return tasksRepository.checkFlag(user.getName(), flag); if(tasksRepository.checkFlag(user.getName(), flag)) {
return Response.ok().build();
}
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment