Skip to content
Snippets Groups Projects
Commit 89e22e7a authored by Stefan Kraus's avatar Stefan Kraus Committed by Tom Kunze
Browse files

server/script.js: only allow new requests after five minutes

parent 9cba3a4f
No related branches found
No related tags found
No related merge requests found
...@@ -120,6 +120,22 @@ function toggleLectureMode() { ...@@ -120,6 +120,22 @@ function toggleLectureMode() {
populateMap(); populateMap();
} }
//Set timecookie from lastRequest
function setLastTutorRequestTime(){
var requestWaitTime = 0 * 60 * 1000; // Wait 5 minutes before a tutor can be requested again.
var date = new Date();
date.setTime(date.getTime() + requestWaitTime);
// Safe time and not date directly, otherwise he saves a string (?) representing this date...
$.cookie('lastTutorRequest', date.getTime());
}
function waitedEnoughTime(){
var lastReq = $.cookie('lastTutorRequest');
return lastReq === undefined || lastReq < (new Date());
}
//sends a request for a tutor and draws tutordata afterwards //sends a request for a tutor and draws tutordata afterwards
function requestTutor(){ function requestTutor(){
if (!isHostInRoom(getHostname(), currentRoom())) { if (!isHostInRoom(getHostname(), currentRoom())) {
...@@ -127,6 +143,12 @@ function requestTutor(){ ...@@ -127,6 +143,12 @@ function requestTutor(){
return; return;
} }
if(!waitedEnoughTime()){
displayErrorPopup("Du hast erst vor kurzem nach einem Tutor gefragt");
return;
}
// FIXME
var lecture = $("#lectureSelector").val(); var lecture = $("#lectureSelector").val();
if (lecture === undefined) { if (lecture === undefined) {
return; return;
...@@ -153,6 +175,8 @@ function cancelTutorRequest(){ ...@@ -153,6 +175,8 @@ function cancelTutorRequest(){
return; return;
} }
setLastTutorRequestTime();
$.ajax(server+"/request", { $.ajax(server+"/request", {
type: "DELETE", type: "DELETE",
data: { data: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment