Last active
August 4, 2020 19:23
-
-
Save GlenMerlin/174ca00378fd6ed56b0487c930f31568 to your computer and use it in GitHub Desktop.
This is a way to have the fictional univeristy website redirect you to the register page with too many failed attempt to like a professor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
var failedAttemptCount = 0 | |
class Like { | |
constructor() { | |
this.events(); | |
} | |
events() { | |
$(".like-box").on("click", this.ourClickDispatcher.bind(this)) | |
} | |
// Methods | |
ourClickDispatcher(e) { | |
var currentLikeBox = $(e.target).closest(".like-box") | |
if(currentLikeBox.data('exists') == "yes") { | |
this.deleteLike(currentLikeBox) | |
} else{ | |
this.createLike(currentLikeBox) | |
} | |
} | |
createLike(currentLikeBox) { | |
$.ajax({ | |
beforeSend: (xhr) => { | |
xhr.setRequestHeader('X-WP-Nonce', universityData.nonce); | |
}, | |
url: universityData.root_url + '/wp-json/university/v1/manageLike', | |
type: 'POST', | |
data: {'professorId': currentLikeBox.data('professor')}, | |
success: (response) => { | |
console.log(response); | |
}, | |
error: (response) => { | |
alert("Oops something went wrong :( \nAre you logged in?") | |
console.log(response) | |
failedAttemptCount++1; | |
console.log(failedAttemptCount) | |
if (failedAttemptCount >= 2) { | |
window.location.href = universityData.root_url + '/wp-login.php?action=register'; | |
} | |
} | |
}) | |
} | |
deleteLike() { | |
$.ajax({ | |
url: universityData.root_url + '/wp-json/university/v1/manageLike', | |
type: 'DELETE', | |
success: (response) => { | |
console.log(response); | |
}, | |
error: (response) => { | |
console.log(response) | |
} | |
}) | |
} | |
} | |
export default Like; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment