mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 03:32:56 +01:00
Unfinished settings + improvements
This commit is contained in:
parent
9d0c60419e
commit
e7b0470653
29
index.js
29
index.js
@ -22,7 +22,7 @@ const __dirname = path.dirname(__filename);
|
||||
|
||||
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.urlencoded({ extended: true }));
|
||||
@ -88,14 +88,21 @@ io.engine.use(sessionMiddleware);
|
||||
app.get('/', async (req, res) => {
|
||||
let login = loginState(req);
|
||||
|
||||
const locale = new Lang(req.acceptsLanguages());
|
||||
|
||||
if (login != 2) {
|
||||
res.redirect('/login');
|
||||
} else if (req.session.nickname == null) {
|
||||
auth.getLanguage(req.session.userId).then(language => {
|
||||
var locale;
|
||||
if (language) {
|
||||
locale = new Lang([language]);
|
||||
req.session.langs = [language];
|
||||
} else {
|
||||
locale = new Lang(req.acceptsLanguages());
|
||||
req.session.langs = req.acceptsLanguages();
|
||||
}
|
||||
|
||||
auth.getNickname(req.session.userId).then(nickname => {
|
||||
if (nickname != null) {
|
||||
req.session.langs = req.acceptsLanguages();
|
||||
req.session.nickname = nickname;
|
||||
|
||||
res.render('index', {
|
||||
@ -107,14 +114,24 @@ app.get('/', async (req, res) => {
|
||||
res.redirect('/nickname');
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
auth.getLanguage(req.session.userId).then(language => {
|
||||
var locale;
|
||||
if (language) {
|
||||
locale = new Lang([language]);
|
||||
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) {
|
||||
if (flags) {
|
||||
return flags.includes(key);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -12,7 +12,8 @@
|
||||
"menu": {
|
||||
"navbar": {
|
||||
"Main menu": "Main menu",
|
||||
"Profile": "Profile"
|
||||
"Profile": "Profile",
|
||||
"Settings": "Settings"
|
||||
},
|
||||
"index": {
|
||||
"Select game mode": "Select game mode",
|
||||
|
@ -12,7 +12,8 @@
|
||||
"menu": {
|
||||
"navbar": {
|
||||
"Main menu": "Menu główne",
|
||||
"Profile": "Profil"
|
||||
"Profile": "Profil",
|
||||
"Settings": "Ustawienia"
|
||||
},
|
||||
"index": {
|
||||
"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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
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> --}}
|
||||
<div class="container" id="mainMenuView" data-path="/">
|
||||
<div>
|
||||
@ -93,6 +93,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container" id="settingsView" data-path="/match">
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.locale = {
|
||||
"Unknown error occured": "{{ t 'menu.General.Unknown error occured' }}",
|
||||
|
Loading…
Reference in New Issue
Block a user