veteran pw request and login page error handle, login page feedback

This commit is contained in:
MrFry 2020-04-09 14:26:39 +02:00
parent 9a6553dbbb
commit 335c431ce4
3 changed files with 94 additions and 25 deletions

@ -1 +1 @@
Subproject commit 42e6d4dd4c86541bc02787a1df3e22ba8f781295 Subproject commit 6d37a88c39dba8763d7672edbb6821e7e156c620

View file

@ -70,12 +70,12 @@
Frylabs Frylabs
</div> </div>
<div id='text' class='text'> <div id='text' class='text'>
Másold be ide régi kliens ID-d, és az alapján jelszót kapsz. Ezt csak egyszer teheted meg, a Másold be ide régi kliens ID-d, és az alapján jelszót kapsz. Ezt csak egyszer teheted meg,
kapott jelszót tuti helyre írd le! ezért a kapott jelszót tuti helyre írd le!
</div> </div>
<div id='form'> <div id='form'>
<div class='inputContainer'> <div class='inputContainer'>
<input type='text' id='cid' name='pw' value=<%= cid %> autocomplete="off"/> <input type='text' id='cid' name='pw' value='<%= cid %>' autocomplete="off"/>
</div> </div>
<input type='hidden' name='redirect' value='asd' autocomplete="off"/> <input type='hidden' name='redirect' value='asd' autocomplete="off"/>
<button id='sendButton' onclick="GetVeteranPW(this)">Submit</button> <button id='sendButton' onclick="GetVeteranPW(this)">Submit</button>
@ -111,10 +111,20 @@
cid: document.getElementById('cid').value cid: document.getElementById('cid').value
}) })
}) })
rawResponse.json() if (!rawResponse.ok) {
.then((resp) => { document.getElementById('text').innerText = 'Internal server error'
HandleResp(resp) document.getElementById('sendButton').innerText = 'Submit'
}) }
try {
rawResponse.json()
.then((resp) => {
HandleResp(resp)
})
} catch (e) {
document.getElementById('text').innerText = 'Invalid data recieved from server'
document.getElementById('sendButton').innerText = 'Submit'
console.log(e)
}
} }
</script> </script>
</html> </html>

View file

@ -39,7 +39,7 @@
width: 40px; width: 40px;
cursor: pointer; cursor: pointer;
} }
input[type=text], input[type=password] { input[type=text], input[type=password], textarea {
font-size: 20px; font-size: 20px;
color: #ffffff; color: #ffffff;
background-color: #181a1b; background-color: #181a1b;
@ -69,6 +69,17 @@
.ircLink { .ircLink {
color: #9999ff; color: #9999ff;
font-size: 12px; font-size: 12px;
text-decoration: underline;
cursor: pointer;
}
#feedback {
display: none;
}
#feedbackTextArea {
text-align: left;
font-size: 16px;
height: 160px;
resize: none;
} }
</style> </style>
</head> </head>
@ -78,31 +89,70 @@
</div> </div>
<div id='text' class='text'> <div id='text' class='text'>
</div> </div>
<div id='feedback'>
<textarea id='feedbackTextArea'></textarea>
<div class='ircLinkContainer' >
<a class='ircLink' href='https://qmining.frylabs.net/irc?loginClick'>IRC</a>
</div>
<button id='sendFeedbackButton' onclick="SendFeedback(this)">Submit</button>
</div>
<div id='form'> <div id='form'>
<div class='inputContainer'> <div class='inputContainer'>
<input type='password' id='pw' name='pw' autocomplete="off"/> <input type='password' id='pw' name='pw' autocomplete="off"/>
<!-- <span onclick="ShowHidePW()" class='showpwContainer'>
👁
</span> -->
</div> </div>
<div class='ircLinkContainer' > <div class='ircLinkContainer' >
<a class='ircLink' href='https://qmining.frylabs.net/irc?loginClick'>Contact</a> <a class='ircLink' onclick='ShowFeedback()'>Contact</a>
</div> </div>
<button id='sendButton' onclick="Login(this)">Submit</button> <button id='sendButton' onclick="Login(this)">Submit</button>
</div> </div>
</div> </div>
</body> </body>
<script> <script>
function ShowHidePW() { function HandleFeedbackResp (resp) {
const x = document.getElementById('pw') document.getElementById('sendButton').innerText = 'Submit'
if (x.type === "password") { const textNode = document.getElementById('text')
x.type = "text"; const feedback = document.getElementById('feedback').style.display = "none";
if (resp.success) {
textNode.innerText = 'Visszajelzés elküldve'
} else { } else {
x.type = "password"; textNode.innerText = 'Szerver oldali hiba :c'
} }
} }
async function SendFeedback (button) {
const feedback = document.getElementById('feedbackTextArea').value
button.innerText = '...'
const rawResponse = await fetch('http://api.frylabs.net/postfeedback', {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: feedback,
fromLogin: true
})
})
if (!rawResponse.ok) {
document.getElementById('text').innerText = 'Internal server error'
button.innerText = 'Submit'
}
try {
rawResponse.json()
.then((resp) => {
HandleFeedbackResp(resp)
})
} catch (e) {
document.getElementById('text').innerText = 'Invalid data recieved from server'
button.innerText = 'Submit'
console.log(e)
}
}
function ShowFeedback () {
const form = document.getElementById('form').style.display = "none";
const feedback = document.getElementById('feedback').style.display = "block";
}
function HandleResp (resp) { function HandleResp (resp) {
console.log(resp)
document.getElementById('sendButton').innerText = 'Submit' document.getElementById('sendButton').innerText = 'Submit'
const textNode = document.getElementById('text') const textNode = document.getElementById('text')
if (resp.result === 'success') { if (resp.result === 'success') {
@ -112,7 +162,6 @@
textNode.innerText = resp.msg textNode.innerText = resp.msg
} }
} }
async function Login(button) { async function Login(button) {
button.innerText = '...' button.innerText = '...'
const rawResponse = await fetch('http://api.frylabs.net/login', { const rawResponse = await fetch('http://api.frylabs.net/login', {
@ -126,10 +175,20 @@
pw: document.getElementById('pw').value pw: document.getElementById('pw').value
}) })
}) })
rawResponse.json() if (!rawResponse.ok) {
.then((resp) => { document.getElementById('text').innerText = 'Internal server error'
HandleResp(resp) button.innerText = 'Submit'
}) }
try {
rawResponse.json()
.then((resp) => {
HandleResp(resp)
})
} catch (e) {
document.getElementById('text').innerText = 'Invalid data recieved from server'
button.innerText = 'Submit'
console.log(e)
}
} }
</script> </script>
</html> </html>