warnings and errors for ath

This commit is contained in:
SpikeHD 2022-04-26 22:15:06 -07:00
parent 81c6eca69c
commit 5730a9700f
5 changed files with 107 additions and 2 deletions

12
resources/icons/alert.svg Normal file
View File

@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05) scale(3.89 3.89)" >
<path d="M 53.789 81.581 C 53.583 86.264 49.733 90 45 90 s -8.584 -3.736 -8.789 -8.419 H 53.789 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
<path d="M 76.051 64.035 c -1.71 -1.463 -2.691 -3.592 -2.691 -5.841 V 36.035 c 0 -15.638 -12.722 -28.36 -28.36 -28.36 c -15.638 0 -28.36 12.722 -28.36 28.36 v 22.159 c 0 2.25 -0.981 4.379 -2.692 5.84 c -2.564 2.189 -4.034 5.378 -4.034 8.751 c 0 2.739 2.228 4.967 4.967 4.967 h 60.235 c 2.74 0 4.968 -2.228 4.968 -4.967 C 80.085 69.412 78.614 66.223 76.051 64.035 z M 48.709 60.728 c 0 2.048 -1.66 3.709 -3.709 3.709 c -2.048 0 -3.709 -1.66 -3.709 -3.709 v -1.422 c 0 -2.048 1.66 -3.709 3.709 -3.709 c 2.048 0 3.709 1.66 3.709 3.709 V 60.728 z M 48.795 49.091 c -0.048 2.062 -1.733 3.708 -3.795 3.708 c -2.062 0 -3.747 -1.646 -3.795 -3.708 L 40.67 26.075 c -0.049 -2.13 1.664 -3.884 3.795 -3.884 h 1.069 c 2.131 0 3.844 1.754 3.795 3.884 L 48.795 49.091 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
<path d="M 38.985 12.2 c -1.057 0 -1.915 -0.857 -1.915 -1.915 V 7.929 C 37.07 3.557 40.628 0 45 0 s 7.929 3.557 7.929 7.929 v 2.355 c 0 1.057 -0.857 1.915 -1.915 1.915 s -1.915 -0.857 -1.915 -1.915 V 7.929 c 0 -2.26 -1.839 -4.1 -4.099 -4.1 c -2.26 0 -4.1 1.839 -4.1 4.1 v 2.356 C 40.9 11.343 40.043 12.2 38.985 12.2 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -11,6 +11,7 @@
<script src="js/onLoad.js"></script>
<script src="js/options.js"></script>
<script src="js/login.js"></script>
<script src="js/authAlert.js"></script>
<script src="js/translation.js"></script>
</head>
<body>
@ -66,6 +67,12 @@
Launch without Authentication
</button>
</div>
<!-- Alert element for any problems that arise -->
<div id="loginAlert" style="display: none">
<img src="icons/alert.svg" />
<span id="loginAlertText"></span>
</div>
</div>
<!-- Register section -->
@ -98,6 +105,12 @@
<div id="registerPopupContentBodyBtns">
<button class="playBtn" id="registerPopupContentBodyBtnRegister" onclick="register()">Register</button>
</div>
<!-- Alert element for any problems that arise -->
<div id="registerAlert" style="display: none">
<img src="icons/alert.svg" />
<span id="registerAlertText"></span>
</div>
</div>
</div>

50
resources/js/authAlert.js Normal file
View File

@ -0,0 +1,50 @@
let alertTimeout, alertCooldown = 3000
async function displayLoginAlert(message, type) {
const elm = document.getElementById('loginAlert');
const text = document.getElementById('loginAlertText');
elm.style.removeProperty('display');
switch(type) {
case 'error':
elm.classList.add('error');
break;
case 'warn':
default:
elm.classList.add('warn');
break;
}
text.innerText = message;
// Disappear after 5 seconds
alertTimeout = setTimeout(() => {
elm.style.display = 'none';
}, alertCooldown)
}
async function displayRegisterAlert(message, type) {
const elm = document.getElementById('registerAlert');
elm.style.removeProperty('display');
switch(type) {
case 'error':
elm.classList.add('error');
break;
case 'warn':
default:
elm.classList.add('warn');
break;
}
text.innerText = message;
// Disappear after 5 seconds
alertTimeout = setTimeout(() => {
elm.style.display = 'none';
}, alertCooldown)
}

View File

@ -63,13 +63,12 @@ async function login() {
}
const { data } = await axios.post(url + '/grasscutter/login', reqBody)
const tkData = parseJwt(data.jwt)
console.log(data)
switch(data.message) {
case 'INVALID_ACCOUNT':
// Username or password invalid
displayLoginAlert('Invalid username or password', 'error');
break;
case 'NO_PASSWORD':
@ -86,6 +85,7 @@ async function login() {
default:
// Success! Copy the JWT token to their clipboard
const tkData = parseJwt(data.jwt)
await Neutralino.clipboard.writeText(tkData.token)
break;
}

View File

@ -117,6 +117,36 @@ body {
margin-right: 6px;
}
.error {
background: #e90000;
}
#registerAlert .warn,
#loginAlert .warn {
}
#registerAlert,
#loginAlert {
display: flex;
justify-content: center;
align-items: center;
border-radius: 5px;
color: #fff;
}
#registerAlert img,
#loginAlert img {
height: 20px;
margin: 10px;
filter: invert(100%) sepia(0%) saturate(179%) hue-rotate(253deg) brightness(105%) contrast(101%);
}
#registerAlert span,
#loginAlert span {
margin: 10px;
}
#firstTimeNotice,
#loginPanel,
#settingsPanel {