Popups and Niceties

This commit is contained in:
2022-05-07 08:02:58 +00:00
parent 60f182b99d
commit e9bf9fd222
6 changed files with 185 additions and 26 deletions

View File

@@ -5,8 +5,20 @@ const dbp = (msg) => {
console.log(msg);
};
const SwalConfig = {
color: "#79F257",
background: "#022601",
}
const isOverflown = ({ clientHeight, scrollHeight }) => scrollHeight > clientHeight
const setCookie = (cname, cvalue, exdays) => {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/auth";
}
const resizeText = ({ element, elements, minSize = 10, maxSize = 512, step = 1, unit = 'px' }) => {
dbp("Resize");
(elements || [element]).forEach(el => {
@@ -63,29 +75,77 @@ const disableNonDesktopElements = () => {
// document.getElementById("bttn").style.height = "15vw";
}
const generateSSH = async (name) => {
const failMsg = (msg) => {
$("#resizer").html(msg);
$("#resizer").css("color", "#400112");
$("#resizer").css("background-color", "#79F257");
$("#resizer").animate({
color: "#79F257",
backgroundColor: "#022601"
}, 1000);
}
const generateSSH = async (name, id, token) => {
dbp("Generate Key");
// debugger;
generateKeyPair("RSASSA-PKCS1-v1_5", 4096, "namehere")
.then((keys) => {
console.dir(keys);
// saveFile("ssh_key.pem", "text/plain", keys[0]);
// saveFile("ssh_key.pub", "text/plain", keys[1]);
var KeyExport = new JSZip();
KeyExport.file("HackersTownTTY-"+name, keys[0]);
KeyExport.file("HackersTownTTY-"+name+".pub", keys[1]);
KeyExport.generateAsync({type:"blob"})
.then((content) => {
saveFile("HackersTownTTY-"+name+".zip", "application/zip", content);
// saveAs(content, "HackersTownTTY-"+name+".zip");
});
});
var payload = {
pubkey: keys[1],
userId: id,
authToken: token
};
$.post("https://tty.hackers.town/auth/setKey.php", payload, (response) => {
console.log(response);
// debugger;
if(response.status){
Swal.fire({
...SwalConfig,
title: "Success!",
});
}else{
Swal.fire({
...SwalConfig,
title: "Failed!",
text: response.error
});
}
}).fail(() => {
console.log("Failed");
});
}).catch((err) => {
console.log(err);
});
}
const uploadSSH = () => {
const testSwal = () => {
Swal.fire({
...SwalConfig,
title: "Success!",
});
}
const uploadSSH = () => {
//request local file
// $("#keyfiie").trigger("click");
var kf = document.getElementById("keyfile");
kf.onchange = function(e) {
// File selected
}
kf.click();
dbp("Nextttt");
//upload file
}
const beginOauth = () => {
@@ -99,16 +159,14 @@ const beginOauth = () => {
"response_type=code&client_id="+data.id+"&redirect_uri="+
"https://tty.hackers.town/auth&scope=read:accounts";
dbp(redirect);
dbp(window.location.pathname);
if(window.location.pathname.includes("auth")){
setCookie("oa_retries", 0, 0.1);
}
window.location.href = redirect;
}else{
// Auth Failed
$("#resizer").html("AUTH FAILED");
$("#resizer").css("color", "#400112");
$("#resizer").css("background-color", "#79F257");
$("#resizer").animate({
color: "#79F257",
backgroundColor: "#022601"
}, 1000);
failMsg("AUTH FAILED");
}
});
}
@@ -126,4 +184,13 @@ $(() => {
dbp("Is Mobile 👍🏻");
disableNonDesktopElements();
}
// Auto Retry
if(window.location.pathname.includes("auth")){
var ErrorMsg = document.getElementById("ErrorResult");
dbp(typeof ErrorMsg);
if(typeof ErrorMsg !== 'undefined' && ErrorMsg.innerText.includes("Retry")){
dbp("attempt retry");
beginOauth();
}
}
});