init
This commit is contained in:
commit
8c889222ce
10 changed files with 4525 additions and 0 deletions
45
account.js
Normal file
45
account.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { initDb } from './db.js';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
let getToken = async (token) => {
|
||||
let db = await initDb();
|
||||
|
||||
let id = '!nobody';
|
||||
|
||||
let username = await fetch("https://nbg.dervland.net/auth.php",
|
||||
{
|
||||
"method": "get",
|
||||
"headers": {
|
||||
"cookie": `token=${token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
username = await username.text();
|
||||
|
||||
try {
|
||||
username = (username.length > 1) ? username : '';
|
||||
|
||||
if (username) id = username;
|
||||
} catch (err) {
|
||||
id = '!nobody';
|
||||
}
|
||||
|
||||
let userExists = await db.all('SELECT * FROM user WHERE username = ?', [
|
||||
id
|
||||
]);
|
||||
|
||||
if (userExists.length < 1) {
|
||||
await db.run('INSERT INTO user (username, roles, nickname) VALUES (?,?,?)', [
|
||||
id,
|
||||
0,
|
||||
id
|
||||
]);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export {
|
||||
getToken
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue