mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 05:22:55 +01:00
Unfinished settings + improvements
This commit is contained in:
parent
9d0c60419e
commit
e7b0470653
61
index.js
61
index.js
@ -22,7 +22,7 @@ const __dirname = path.dirname(__filename);
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const flags = process.env.flags.split(",");
|
const flags = process.env.flags ? process.env.flags.split(",") : null;
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
@ -88,32 +88,49 @@ io.engine.use(sessionMiddleware);
|
|||||||
app.get('/', async (req, res) => {
|
app.get('/', async (req, res) => {
|
||||||
let login = loginState(req);
|
let login = loginState(req);
|
||||||
|
|
||||||
const locale = new Lang(req.acceptsLanguages());
|
|
||||||
|
|
||||||
if (login != 2) {
|
if (login != 2) {
|
||||||
res.redirect('/login');
|
res.redirect('/login');
|
||||||
} else if (req.session.nickname == null) {
|
} else if (req.session.nickname == null) {
|
||||||
auth.getNickname(req.session.userId).then(nickname => {
|
auth.getLanguage(req.session.userId).then(language => {
|
||||||
if (nickname != null) {
|
var locale;
|
||||||
req.session.langs = req.acceptsLanguages();
|
if (language) {
|
||||||
req.session.nickname = nickname;
|
locale = new Lang([language]);
|
||||||
|
req.session.langs = [language];
|
||||||
res.render('index', {
|
|
||||||
helpers: {
|
|
||||||
t: (key) => { return locale.t(key) }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
res.redirect('/nickname');
|
locale = new Lang(req.acceptsLanguages());
|
||||||
|
req.session.langs = req.acceptsLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth.getNickname(req.session.userId).then(nickname => {
|
||||||
|
if (nickname != null) {
|
||||||
|
req.session.nickname = nickname;
|
||||||
|
|
||||||
|
res.render('index', {
|
||||||
|
helpers: {
|
||||||
|
t: (key) => { return locale.t(key) }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.redirect('/nickname');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
req.session.langs = req.acceptsLanguages();
|
auth.getLanguage(req.session.userId).then(language => {
|
||||||
|
var locale;
|
||||||
res.render('index', {
|
if (language) {
|
||||||
helpers: {
|
locale = new Lang([language]);
|
||||||
t: (key) => { return locale.t(key) }
|
req.session.langs = [language];
|
||||||
|
} else {
|
||||||
|
locale = new Lang(req.acceptsLanguages());
|
||||||
|
req.session.langs = req.acceptsLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.render('index', {
|
||||||
|
helpers: {
|
||||||
|
t: (key) => { return locale.t(key) }
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -637,5 +654,9 @@ function getIP(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkFlag(key) {
|
function checkFlag(key) {
|
||||||
return flags.includes(key);
|
if (flags) {
|
||||||
|
return flags.includes(key);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,7 +12,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"navbar": {
|
"navbar": {
|
||||||
"Main menu": "Main menu",
|
"Main menu": "Main menu",
|
||||||
"Profile": "Profile"
|
"Profile": "Profile",
|
||||||
|
"Settings": "Settings"
|
||||||
},
|
},
|
||||||
"index": {
|
"index": {
|
||||||
"Select game mode": "Select game mode",
|
"Select game mode": "Select game mode",
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"navbar": {
|
"navbar": {
|
||||||
"Main menu": "Menu główne",
|
"Main menu": "Menu główne",
|
||||||
"Profile": "Profil"
|
"Profile": "Profil",
|
||||||
|
"Settings": "Ustawienia"
|
||||||
},
|
},
|
||||||
"index": {
|
"index": {
|
||||||
"Select game mode": "Wybierz tryb gry",
|
"Select game mode": "Wybierz tryb gry",
|
||||||
|
@ -88,6 +88,21 @@ export class MailAuth {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLanguage(userId) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const conn = mysql.createConnection(this.mysqlOptions);
|
||||||
|
conn.query(`SELECT language FROM accounts WHERE user_id = ${conn.escape(userId)}`, (error, response) => {
|
||||||
|
if (error) { reject(error); return; }
|
||||||
|
|
||||||
|
if (response.length !== 0) {
|
||||||
|
resolve(response[0].language);
|
||||||
|
} else {
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
startVerification(email, ip, agent) {
|
startVerification(email, ip, agent) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const conn = mysql.createConnection(this.mysqlOptions);
|
const conn = mysql.createConnection(this.mysqlOptions);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<nav><span onclick="switchView('mainMenuView')">{{ t 'menu.navbar.Main menu' }}</span> <span id="profileButton" onclick="switchView('profileView')">{{ t 'menu.navbar.Profile' }}</span></nav>
|
<nav><span onclick="switchView('settingsView')">{{ t 'menu.navbar.Settings' }}</span><span onclick="switchView('mainMenuView')">{{ t 'menu.navbar.Main menu' }}</span> <span id="profileButton" onclick="switchView('profileView')">{{ t 'menu.navbar.Profile' }}</span></nav>
|
||||||
{{!-- <h1 class="header">Statki</h1> --}}
|
{{!-- <h1 class="header">Statki</h1> --}}
|
||||||
<div class="container" id="mainMenuView" data-path="/">
|
<div class="container" id="mainMenuView" data-path="/">
|
||||||
<div>
|
<div>
|
||||||
@ -93,6 +93,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="container" id="settingsView" data-path="/match">
|
||||||
|
<div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.locale = {
|
window.locale = {
|
||||||
"Unknown error occured": "{{ t 'menu.General.Unknown error occured' }}",
|
"Unknown error occured": "{{ t 'menu.General.Unknown error occured' }}",
|
||||||
|
Loading…
Reference in New Issue
Block a user