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 {
}
}
private boolean compareHash(String hash, String username) throws Exception {
Task task = getUserFlagsHashes(username).get(hash);
if (task != null) {
public boolean checkFlag(String username, String flagValue) throws Exception {
Task task = getUserFlagsHashes(username).get(flagValue);
if(task != null) {
acceptSolution(username, task);
return true;
}
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) {
//todo: taskId, level, name? discuss
return getUserFlagsHashes(username).entrySet().stream()
......
......@@ -63,9 +63,12 @@ public class TasksResource
//todo: move to solutions resource
@POST
public boolean submitSolution(@Auth User user,
String flag) throws Exception {
return tasksRepository.checkFlag(user.getName(), flag);
public Response submitSolution(@Auth User user,
String flag) throws Exception {
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