login and register functions

This commit is contained in:
SpikeHD 2022-04-26 21:16:12 -07:00
parent 97bd0f239f
commit 104b54d820
2 changed files with 60 additions and 12 deletions

View File

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<link rel="stylesheet" type="text/css" href="style/index.css" /> <link rel="stylesheet" type="text/css" href="style/index.css" />
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="js/neutralino.js"></script> <script src="js/neutralino.js"></script>
<script src="js/windowDrag.js"></script> <script src="js/windowDrag.js"></script>
<script src="js/hoverEvt.js"></script> <script src="js/hoverEvt.js"></script>

View File

@ -47,24 +47,71 @@ async function login() {
password, password,
} }
// Send the request const { data } = await axios.post(url + '/grasscutter/login', reqBody)
const response = await fetch(url + '/grasscutter/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(reqBody),
mode: 'no-cors',
}).catch(e => {
console.log(e)
})
console.log(response) console.log(data)
switch(data.message) {
case 'INVALID_ACCOUNT':
// Username or password invalid
break;
case 'NO_PASSWORD':
// No account password, create one with change password
break;
case 'UNKNOWN':
// Unknown error, contact server owner
break;
case 'AUTH_DISABLED':
// Authentication is disabled, we can just connect the user
break;
default:
// Success! Copy the JWT token to their clipboard
break;
}
} }
/** /**
* Attempt registration, do not launch game * Attempt registration, do not launch game
*/ */
async function register() { async function register() {
const username = document.getElementById('registerUsername').value;
const password = document.getElementById('registerPassword').value;
const password_confirmation = document.getElementById('registerPasswordConfirm').value;
const ip = document.getElementById('ip').value;
const port = document.getElementById('port').value || '443';
const config = await getCfg();
const useHttps = config.useHttps;
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`;
const reqBody = {
username,
password,
password_confirmation
}
const { data } = await axios.post(url + '/grasscutter/register', reqBody)
console.log(data)
switch(data.message) {
case 'USERNAME_TAKEN':
// Username is taken
break;
case 'PASSWORD_MISMATCH':
// The password and password confirmation do not match
break;
case 'UNKNOWN':
// Unknown error, contact server owner
break;
case 'AUTH_DISABLED':
// Authentication is disabled, we can just connect the user
break;
}
} }