mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 03:42:55 +01:00
Fixed logging in/creating account
This commit is contained in:
parent
66b00c81e1
commit
e0f7137f16
2
index.js
2
index.js
@ -376,7 +376,7 @@ io.on('connection', async (socket) => {
|
||||
|
||||
let UTCTs = Math.floor((new Date()).getTime() / 1000 + 90);
|
||||
io.to(playerGame.id).emit('turn update', { turn: 0, phase: "preparation", timerToUTC: UTCTs });
|
||||
GInfo.timer(playerGame.id, 10, async () => {
|
||||
GInfo.timer(playerGame.id, 90, async () => {
|
||||
const playerGame = await GInfo.getPlayerGameData(socket);
|
||||
for (let i = 0; i < playerGame.data.boards.length; i++) {
|
||||
const ships = playerGame.data.boards[i].ships;
|
||||
|
@ -196,3 +196,4 @@ socket.on('player left', () => {
|
||||
window.location.replace("/");
|
||||
});
|
||||
// SELECT ROUND((1 - AVG(statistics.won)) * 100) AS winrate, COUNT(statistics.match_id) AS alltime_matches, COUNT(CASE WHEN (YEAR(matches.date) = YEAR(NOW()) AND MONTH(matches.date) = MONTH(NOW())) THEN matches.match_id END) AS monthly_matches FROM accounts NATURAL JOIN statistics NATURAL JOIN matches WHERE accounts.nickname = "MaciejkaG";
|
||||
//
|
2
public/assets/js/test.sql
Normal file
2
public/assets/js/test.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- SELECT nickname, host_id, board, match_type, date FROM accounts NATURAL JOIN statistics JOIN matches ON matches.host_id = accounts.user_id WHERE nickname = "deeznuts24";
|
||||
SELECT accounts.nickname, statistics.board, matches.match_type, matches.duration, date FROM statistics JOIN matches ON statistics.match_id = matches.match_id NATURAL JOIN accounts me JOIN accounts opp ON matches.guest_id = a WHERE me.nickname = "deeznuts24";
|
@ -15,8 +15,6 @@ const rl = readline.createInterface({
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const saltRounds = 10;
|
||||
|
||||
export class MailAuth {
|
||||
constructor(redis, options, mysqlOptions) {
|
||||
this.redis = redis;
|
||||
@ -66,15 +64,19 @@ export class MailAuth {
|
||||
const conn = mysql.createConnection(this.mysqlOptions);
|
||||
conn.query(`SELECT user_id, nickname FROM accounts WHERE email = ${conn.escape(email)}`, async (error, response) => {
|
||||
if (error) { reject(error); return; }
|
||||
if (response.length !== 0) {
|
||||
let timer = await this.redis.get(`loginTimer:${response[0].user_id}`);
|
||||
if (response.length !== 0 && timer && timer > 0) {
|
||||
if (timer && timer > 0) {
|
||||
resolve({ status: -1, uid: response[0].user_id });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (response.length === 0 || response[0].nickname == null) {
|
||||
|
||||
if (response.length === 0) {
|
||||
conn.query(`INSERT INTO accounts(email) VALUES (${conn.escape(email)});`, (error) => { if (error) reject(error) });
|
||||
}
|
||||
|
||||
conn.query(`SELECT user_id, nickname FROM accounts WHERE email = ${conn.escape(email)}`, async (error, response) => {
|
||||
if (error) reject(error);
|
||||
const row = response[0];
|
||||
@ -82,7 +84,7 @@ export class MailAuth {
|
||||
const html = fs.readFileSync(path.join(__dirname, 'mail/auth-code-firsttime.html'), 'utf8');
|
||||
let authCode = genCode();
|
||||
|
||||
await this.redis.json.set(`codeAuth:${authCode}`, "$", { uid: row.user_id, tid: tId });
|
||||
await this.redis.set(`codeAuth:${authCode}`, row.user_id);
|
||||
|
||||
await this.timer(row.user_id, 600, async () => {
|
||||
await this.redis.json.del(`codeAuth:${authCode}`);
|
||||
|
Loading…
Reference in New Issue
Block a user