diff --git a/index.js b/index.js index b22031f..d6f02aa 100644 --- a/index.js +++ b/index.js @@ -208,7 +208,10 @@ app.post('/api/login', (req, res) => { return; } - auth.startVerification(req.body.email, getIP(req), req.get('user-agent')).then(async result => { + + const locale = new Lang(req.acceptsLanguages()); + + auth.startVerification(req.body.email, getIP(req), req.get('user-agent'), locale.lang).then(async result => { if (result.status === 1 || result.status === -1) { req.session.userId = result.uid; diff --git a/utils/auth.js b/utils/auth.js index 567a793..bb50f6d 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -102,7 +102,7 @@ export class MailAuth { }); } - startVerification(email, ip, agent) { + startVerification(email, ip, agent, langId) { return new Promise((resolve, reject) => { const conn = mysql.createConnection(this.mysqlOptions); conn.query(`SELECT user_id, nickname FROM accounts WHERE email = ${conn.escape(email)}`, async (error, response) => { @@ -125,7 +125,7 @@ export class MailAuth { if (error) reject(error); const row = response[0]; - const html = fs.readFileSync(path.join(__dirname, 'mail/auth-code-firsttime.html'), 'utf8'); + const html = fs.readFileSync(path.join(__dirname, `mail/auth-code-firsttime-${langId}.html`), 'utf8'); let authCode = genCode(); await this.redis.set(`codeAuth:${authCode}`, row.user_id); @@ -160,7 +160,7 @@ export class MailAuth { const row = response[0]; - const html = fs.readFileSync(path.join(__dirname, 'mail/auth-code.html'), 'utf8'); + const html = fs.readFileSync(path.join(__dirname, `mail/auth-code-${langId}.html`), 'utf8'); let authCode = genCode(); await this.redis.set(`codeAuth:${authCode}`, row.user_id); @@ -173,7 +173,7 @@ export class MailAuth { const lookup = geoip.lookup(ip); - const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}`; + const lookupData = `User-Agent: ${agent}\nIP address: ${ip}\nCountry: ${lookup.country}\nRegion: ${lookup.region}\nCity: ${lookup.city}`; try { await this.mail.sendMail({ diff --git a/utils/localisation.js b/utils/localisation.js index 03d891e..12a7618 100644 --- a/utils/localisation.js +++ b/utils/localisation.js @@ -45,7 +45,5 @@ export class Lang { } } } - - } diff --git a/utils/mail/auth-code-en.html b/utils/mail/auth-code-en.html new file mode 100644 index 0000000..e842ea1 --- /dev/null +++ b/utils/mail/auth-code-en.html @@ -0,0 +1,34 @@ + + + +
+ + + + + + +Someone tried to log in to Statki using your account, if it wasn't you, ignore this
+ message.
The authorisation code is below, remember to not share it with anyone.
Following code expires after 10 minutes
+Below is some information about a logging in device*
+{{ LOOKUP }}+
* Geolocation data may not be accurate.
+Copyright © 2024 MCJK | statki.maciejka.xyz
This message has been
+ sent automatically, do not reply to it.
For support, message biz@maciejka.xyz
Someone tried to create a Statki (battleships) account with this e-mail. If it wasn't you, ignore this
+ message.
The authorisation code is below, remember to not share it with anyone.
Following code expires after 10 minutes
+Below is some information about a logging in device*
+{{ LOOKUP }}+
* Geolocation data may not be accurate.
+Copyright © 2024 MCJK | statki.maciejka.xyz
This message has been
+ sent automatically, do not reply to it.
For support, message biz@maciejka.xyz
Powyższy kod wygasa po 10 minutach
Poniżej znajdują się informacje o logującym się urządzeniu*
{{ LOOKUP }}-
* Dane lokalizacyjne mogą mijać się z prawdą. Traktuj je z dystansem
+* Dane lokalizacyjne mogą nie być dokładne.
Copyright © 2024 MCJK | statki.maciejka.xyz
Ta wiadomość została
- wysłana automatycznie, nie odpowiadaj na nią.