Added 'altcha' captcha system for account and channel creation.
This commit is contained in:
parent
60801f0dc2
commit
e0f53df176
20 changed files with 326 additions and 55 deletions
|
|
@ -187,21 +187,45 @@ class canopyUXUtils{
|
|||
}
|
||||
|
||||
createPopup(){
|
||||
this.popupBacker = document.createElement('div');
|
||||
this.popupBacker.classList.add('popup-backer');
|
||||
//Check if another popup has already thrown a backer up
|
||||
if(document.querySelector('.popup-backer') == null){
|
||||
//Create popup backer
|
||||
this.popupBacker = document.createElement('div');
|
||||
this.popupBacker.classList.add('popup-backer');
|
||||
}
|
||||
|
||||
//Create popup
|
||||
this.popupDiv = document.createElement('div');
|
||||
this.popupDiv.classList.add('popup-div');
|
||||
|
||||
//Create close icon
|
||||
this.closeIcon = document.createElement('i');
|
||||
this.closeIcon.classList.add('bi-x','popup-close-icon');
|
||||
this.closeIcon.addEventListener("click", this.closePopup.bind(this));
|
||||
|
||||
//Create content div
|
||||
this.contentDiv = document.createElement('div');
|
||||
this.contentDiv.classList.add('popup-content-div');
|
||||
|
||||
//Append popup innards
|
||||
this.popupDiv.appendChild(this.closeIcon);
|
||||
this.popupDiv.appendChild(this.contentDiv);
|
||||
|
||||
|
||||
//Bit hacky but the only way to remove an event listener while keeping the function bound to this
|
||||
//Isn't javascript precious?
|
||||
this.keyClose = ((event)=>{
|
||||
//If we hit enter
|
||||
if(event.key == "Enter"){
|
||||
//Close the pop-up
|
||||
this.closePopup();
|
||||
//Remove this event listener
|
||||
document.removeEventListener('keydown', this.keyClose);
|
||||
}
|
||||
}).bind(this);
|
||||
|
||||
//Add event listener to close popup when enter is hit
|
||||
document.addEventListener('keydown', this.keyClose);
|
||||
}
|
||||
|
||||
async fillPopupContent(){
|
||||
|
|
@ -221,13 +245,31 @@ class canopyUXUtils{
|
|||
}
|
||||
|
||||
displayPopup(){
|
||||
//Blur active element that probably caused the popup
|
||||
document.activeElement.blur();
|
||||
|
||||
//display the popup
|
||||
document.body.prepend(this.popupDiv);
|
||||
document.body.prepend(this.popupBacker);
|
||||
|
||||
//if we created a popup backer
|
||||
if(this.popupBacker != null){
|
||||
//display the popup backer
|
||||
document.body.prepend(this.popupBacker);
|
||||
}
|
||||
}
|
||||
|
||||
closePopup(){
|
||||
//Take out the popup
|
||||
this.popupDiv.remove();
|
||||
this.popupBacker.remove();
|
||||
|
||||
//Look for the backer instead of using the object property since the bitch mighta been created by someone else
|
||||
const foundBacker = document.querySelector('.popup-backer');
|
||||
|
||||
//if there aren't any more popups
|
||||
if(document.querySelector('.popup-div') == null && foundBacker != null){
|
||||
//Take out the backer
|
||||
foundBacker.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -346,13 +388,13 @@ class canopyAjaxUtils{
|
|||
|
||||
}
|
||||
|
||||
async register(user, pass, passConfirm, email){
|
||||
async register(user, pass, passConfirm, email, verification){
|
||||
var response = await fetch(`/api/account/register`,{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(email ? {user, pass, passConfirm, email} : {user, pass, passConfirm})
|
||||
body: JSON.stringify(email ? {user, pass, passConfirm, email, verification} : {user, pass, passConfirm, verification})
|
||||
});
|
||||
|
||||
if(response.status == 200){
|
||||
|
|
@ -435,13 +477,13 @@ class canopyAjaxUtils{
|
|||
}
|
||||
}
|
||||
|
||||
async newChannel(name, description, thumbnail){
|
||||
async newChannel(name, description, thumbnail, verification){
|
||||
var response = await fetch(`/api/channel/register`,{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(thumbnail ? {name, description, thumbnail} : {name, description})
|
||||
body: JSON.stringify(thumbnail ? {name, description, thumbnail, verification} : {name, description, verification})
|
||||
});
|
||||
|
||||
if(response.status == 200){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue