Commit 5968a7da authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

add i18n dependency and test

parent 5f14adea
......@@ -8,6 +8,7 @@ const bodyParser = require('body-parser');
const session = require('express-session');
const errorhandler = require('errorhandler');
const flash = require('express-flash');
const i18n = require('i18n'); // internationalization
var env = process.env.NODE_ENV || 'development';
const config = require('./config/config')[env];
......@@ -47,10 +48,17 @@ app.use(function(req, res, next) {
next();
});
require('./routes/routes')(app, config, passport);
// internationalization (i18n)
i18n.configure({
locales:['de', 'en'],
directory: './locales'
});
app.use(i18n.init);
require('./routes/routes')(app, config, passport, i18n);
//require('./routes/dbconn')(app, config);
require('./routes/api')(app, config, passport);
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
});
\ No newline at end of file
{
"Hello World": "Hallo Welt",
"Hello": "Hallo"
}
\ No newline at end of file
{
"Hello World": "Hello World",
"Hello": "Hello",
}
\ No newline at end of file
......@@ -748,6 +748,19 @@
}
}
},
"i18n": {
"version": "0.8.5",
"resolved": "https://registry.npmjs.org/i18n/-/i18n-0.8.5.tgz",
"integrity": "sha512-6UgLbhJGgn4XFeuZc/dDdrrri0ij24EK4hxv4Pbi5hloYAZ1B2+0eQchEryBFezLKYOHhVGV/5+H4i0oxng94w==",
"requires": {
"debug": "*",
"make-plural": "^6.0.1",
"math-interval-parser": "^2.0.1",
"messageformat": "^2.3.0",
"mustache": "*",
"sprintf-js": "^1.1.2"
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
......@@ -982,6 +995,16 @@
"pify": "^3.0.0"
}
},
"make-plural": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/make-plural/-/make-plural-6.0.1.tgz",
"integrity": "sha512-h0uBNi4tpDkiWUyYKrJNj8Kif6q3Ba5zp/8jnfPy3pQE+4XcTj6h3eZM5SYVUyDNX9Zk69Isr/dx0I+78aJUaQ=="
},
"math-interval-parser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/math-interval-parser/-/math-interval-parser-2.0.1.tgz",
"integrity": "sha512-VmlAmb0UJwlvMyx8iPhXUDnVW1F9IrGEd9CIOmv+XL8AErCUUuozoDMrgImvnYt2A+53qVX/tPW6YJurMKYsvA=="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
......@@ -992,6 +1015,36 @@
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"messageformat": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/messageformat/-/messageformat-2.3.0.tgz",
"integrity": "sha512-uTzvsv0lTeQxYI2y1NPa1lItL5VRI8Gb93Y2K2ue5gBPyrbJxfDi/EYWxh2PKv5yO42AJeeqblS9MJSh/IEk4w==",
"requires": {
"make-plural": "^4.3.0",
"messageformat-formatters": "^2.0.1",
"messageformat-parser": "^4.1.2"
},
"dependencies": {
"make-plural": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/make-plural/-/make-plural-4.3.0.tgz",
"integrity": "sha512-xTYd4JVHpSCW+aqDof6w/MebaMVNTVYBZhbB/vi513xXdiPT92JMVCo0Jq8W2UZnzYRFeVbQiQ+I25l13JuKvA==",
"requires": {
"minimist": "^1.2.0"
}
}
}
},
"messageformat-formatters": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/messageformat-formatters/-/messageformat-formatters-2.0.1.tgz",
"integrity": "sha512-E/lQRXhtHwGuiQjI7qxkLp8AHbMD5r2217XNe/SREbBlSawe0lOqsFb7rflZJmlQFSULNLIqlcjjsCPlB3m3Mg=="
},
"messageformat-parser": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/messageformat-parser/-/messageformat-parser-4.1.2.tgz",
"integrity": "sha512-7dWuifeyldz7vhEuL96Kwq1fhZXBW+TUfbnHN4UCrCxoXQTYjHnR78eI66Gk9LaLLsAvzPNVJBaa66DRfFNaiA=="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
......@@ -1045,6 +1098,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"mustache": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.0.0.tgz",
"integrity": "sha512-FJgjyX/IVkbXBXYUwH+OYwQKqWpFPLaLVESd70yHjSDunwzV2hZOoTBvPf4KLoxesUzzyfTH6F784Uqd7Wm5yA=="
},
"mysql": {
"version": "2.17.1",
"resolved": "https://registry.npmjs.org/mysql/-/mysql-2.17.1.tgz",
......@@ -1686,6 +1744,11 @@
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
},
"sprintf-js": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug=="
},
"sqlstring": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
......
......@@ -11,7 +11,7 @@ const async = require('async')
const crypto = require('crypto')
const nodemailer = require('nodemailer')
module.exports = function (app, config, passport) {
module.exports = function (app, config, passport, i18n) {
// =========== PASSPORT =======
passport.serializeUser(function (user, done) {
......@@ -54,17 +54,6 @@ module.exports = function (app, config, passport) {
passport.use(samlStrategy);
// ============================
/*
app.all('/', function(req, res){
req.flash('test', 'it worked');
res.redirect('/test')
});
app.all('/test', function(req, res){
res.send(JSON.stringify(req.flash('test')));
});
*/
// ============= SAML ==============
app.post(config.passport.saml.path,
passport.authenticate(config.passport.strategy,
......@@ -111,17 +100,34 @@ module.exports = function (app, config, passport) {
"We would like to notify that your password has been successfully updated.\n\n"+
"Thanks,\nM4_LAB Team"
var updatePasswordMailSubject = "Your M4_LAB Password has been updated"
// ================ test i18n ==================
i18n.setLocale('de');
app.get('/de', function(req, res) {
var greeting = i18n.__('Hello World')
res.send(greeting)
});
// ======== APP ROUTES ====================
app.get('/', function (req, res) {
res.redirect('/profile')
app.get('/account', function (req, res) {
if (req.isAuthenticated()) {
methods.getUserByEmail(req.user.email, function(data, err){
if (!err) {
res.render('home', {
greeting: i18n.__('Hello'),
});
}
})
} else {
res.redirect('/account/login');
}
});
app.get('/error', function (req, res) {
res.render('error')
});
app.get('/login',
app.get('/account/login',
passport.authenticate(config.passport.strategy,
{
successRedirect: '/account/',
......@@ -131,7 +137,7 @@ module.exports = function (app, config, passport) {
app.get('/logout', function (req, res) {
if (req.user == null) {
return res.redirect('/account/');
return res.redirect('https://m4lab.hft-stuttgart.de');
}
req.user.nameID = req.user.id;
......@@ -151,7 +157,7 @@ module.exports = function (app, config, passport) {
});
});
app.get('/profile', function (req, res) {
app.get('/account/profile', function (req, res) {
if (req.isAuthenticated()) {
methods.getUserByEmail(req.user.email, function(data, err){
if (!err) {
......@@ -166,7 +172,7 @@ module.exports = function (app, config, passport) {
}
});
app.get('/services', function (req, res) {
app.get('/account/services', function (req, res) {
if (req.isAuthenticated()) {
async.waterfall([
// get userId by email from userdb
......@@ -230,7 +236,7 @@ module.exports = function (app, config, passport) {
}
});
app.get('/security', function (req, res) {
app.get('/account/security', function (req, res) {
if (req.isAuthenticated()) {
res.render('security', {
user: req.user // useful for view engine, useless for HTML
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment