Commit a1499b82 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files
parents 6f364054 5140687d
...@@ -62,26 +62,26 @@ module.exports = function (app, config, passport, i18n) { ...@@ -62,26 +62,26 @@ module.exports = function (app, config, passport, i18n) {
failureFlash: true failureFlash: true
}), }),
function (req, res) { function (req, res) {
res.redirect('/account/'); res.redirect('/');
} }
); );
// to generate Service Provider's XML metadata // to generate Service Provider's XML metadata
app.get('/saml/metadata', app.get('/saml/metadata',
function(req, res) { function(req, res) {
res.type('application/xml'); res.type('application/xml');
var spMetadata = samlStrategy.generateServiceProviderMetadata(fs.readFileSync(__dirname + '/cert/cert.pem', 'utf8')); var spMetadata = samlStrategy.generateServiceProviderMetadata(fs.readFileSync(__dirname + '/cert/cert.pem', 'utf8'));
res.status(200).send(spMetadata); res.status(200).send(spMetadata);
} }
); );
// ================ test i18n ================== // ================ test i18n ==================
i18n.setLocale('de'); i18n.setLocale('de');
app.get('/de', function(req, res) { app.get('/de', function(req, res) {
var greeting = i18n.__('Hello World') var greeting = i18n.__('Hello World')
res.send(greeting) res.send(greeting)
}); });
var lang = 'DE' var lang = 'DE'
// ======== APP ROUTES - ACCOUNT ==================== // ======== APP ROUTES - ACCOUNT ====================
...@@ -104,8 +104,8 @@ module.exports = function (app, config, passport, i18n) { ...@@ -104,8 +104,8 @@ module.exports = function (app, config, passport, i18n) {
} }
}) })
} else { } else {
res.redirect('/account/login'); // localhost res.redirect('/login'); // localhost
} }
}); });
app.get('/error', function (req, res) { app.get('/error', function (req, res) {
...@@ -122,14 +122,14 @@ module.exports = function (app, config, passport, i18n) { ...@@ -122,14 +122,14 @@ module.exports = function (app, config, passport, i18n) {
app.get('/logout', function (req, res) { app.get('/logout', function (req, res) {
if (req.user == null) { if (req.user == null) {
return res.redirect('/account/'); return res.redirect('/');
} }
req.user.nameID = req.user.id; req.user.nameID = req.user.id;
req.user.nameIDFormat = req.user.idFormat; req.user.nameIDFormat = req.user.idFormat;
return samlStrategy.logout(req, function(err, uri) { return samlStrategy.logout(req, function(err, uri) {
req.logout(); req.logout();
if ( req.session ) { if ( req.session ) {
req.session.destroy((err) => { req.session.destroy((err) => {
if(err) { if(err) {
...@@ -137,7 +137,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -137,7 +137,7 @@ module.exports = function (app, config, passport, i18n) {
} }
}); });
} }
return res.redirect(uri); return res.redirect(uri);
}); });
}); });
...@@ -153,7 +153,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -153,7 +153,7 @@ module.exports = function (app, config, passport, i18n) {
} }
}) })
} else { } else {
res.redirect('/account/login'); res.redirect('/login');
} }
}); });
...@@ -187,7 +187,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -187,7 +187,7 @@ module.exports = function (app, config, passport, i18n) {
// create JSON object of projects and user status for front-end // create JSON object of projects and user status for front-end
function(userProjects, projectsOverview, done) { function(userProjects, projectsOverview, done) {
var allProjects = [] // JSON object var allProjects = [] // JSON object
var userProjectId = [] // array of user's project_id var userProjectId = [] // array of user's project_id
for (var i = 0; i < userProjects.length; i++) { for (var i = 0; i < userProjects.length; i++) {
userProjectId.push(userProjects[i].project_id) userProjectId.push(userProjects[i].project_id)
...@@ -217,7 +217,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -217,7 +217,7 @@ module.exports = function (app, config, passport, i18n) {
} }
]) ])
} else { } else {
res.redirect('/account/login'); res.redirect('/login');
} }
}); });
...@@ -227,7 +227,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -227,7 +227,7 @@ module.exports = function (app, config, passport, i18n) {
user: req.user // useful for view engine, useless for HTML user: req.user // useful for view engine, useless for HTML
}); });
} else { } else {
res.redirect('/account/login'); res.redirect('/login');
} }
}); });
...@@ -242,7 +242,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -242,7 +242,7 @@ module.exports = function (app, config, passport, i18n) {
industry: req.body.inputIndustry, industry: req.body.inputIndustry,
speciality: req.body.inputSpeciality, speciality: req.body.inputSpeciality,
} }
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
if (userData.email) { if (userData.email) {
dbconn.user.query('UPDATE user SET ? WHERE email = "' +userData.email+'"', userData, function (err, rows, fields) { dbconn.user.query('UPDATE user SET ? WHERE email = "' +userData.email+'"', userData, function (err, rows, fields) {
...@@ -257,10 +257,10 @@ module.exports = function (app, config, passport, i18n) { ...@@ -257,10 +257,10 @@ module.exports = function (app, config, passport, i18n) {
}) })
} }
} else { } else {
res.redirect('/account/login'); res.redirect('/login');
} }
}); });
app.post('/changePwd', function (req, res) { app.post('/changePwd', function (req, res) {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
var currPwd = req.body.inputCurrPwd var currPwd = req.body.inputCurrPwd
...@@ -272,7 +272,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -272,7 +272,7 @@ module.exports = function (app, config, passport, i18n) {
// Load hashed passwd from DB // Load hashed passwd from DB
dbconn.user.query('SELECT password FROM credential WHERE user_id='+userId, function (err, rows, fields) { dbconn.user.query('SELECT password FROM credential WHERE user_id='+userId, function (err, rows, fields) {
if (err) { if (err) {
res.redirect('/account/500') res.redirect('/500')
throw err throw err
} }
var userPwd = rows[0].password var userPwd = rows[0].password
...@@ -280,14 +280,14 @@ module.exports = function (app, config, passport, i18n) { ...@@ -280,14 +280,14 @@ module.exports = function (app, config, passport, i18n) {
// check if the password is correct // check if the password is correct
bcrypt.compare(currPwd, userPwd, function(err, isMatch) { bcrypt.compare(currPwd, userPwd, function(err, isMatch) {
if (err) { if (err) {
res.redirect('/account/500') res.redirect('/500')
throw err throw err
} }
else if (!isMatch) { else if (!isMatch) {
//req.flash('error', "Sorry, your password was incorrect. Please double-check your password.") //req.flash('error', "Sorry, your password was incorrect. Please double-check your password.")
req.flash('error', "Das Passwort ist leider falsch. Bitte überprüfen Sie Ihre Eingabe.") req.flash('error', "Das Passwort ist leider falsch. Bitte überprüfen Sie Ihre Eingabe.")
//res.redirect('/account/security') //res.redirect('/security')
res.redirect('/account/security') res.redirect('/security')
} }
else { else {
if ( newPwd != retypePwd ) { if ( newPwd != retypePwd ) {
...@@ -321,19 +321,19 @@ module.exports = function (app, config, passport, i18n) { ...@@ -321,19 +321,19 @@ module.exports = function (app, config, passport, i18n) {
} }
}); });
} }
res.redirect('/account/security') res.redirect('/security')
}) })
}); });
}); });
} }
} }
}) })
}) })
} }
}) })
} }
else { else {
res.redirect('/account/login'); res.redirect('/login');
} }
}); });
...@@ -351,7 +351,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -351,7 +351,7 @@ module.exports = function (app, config, passport, i18n) {
"we've received a request to reset your password. However, this email address is not on our database of registered users.\n\n"+ "we've received a request to reset your password. However, this email address is not on our database of registered users.\n\n"+
"Thanks,\nM4_LAB Team"; "Thanks,\nM4_LAB Team";
var emailSubject = "Account Access Attempted"; */ var emailSubject = "Account Access Attempted"; */
async.waterfall([ async.waterfall([
function(done) { function(done) {
crypto.randomBytes(20, function(err, buf) { crypto.randomBytes(20, function(err, buf) {
...@@ -408,8 +408,8 @@ module.exports = function (app, config, passport, i18n) { ...@@ -408,8 +408,8 @@ module.exports = function (app, config, passport, i18n) {
//req.flash('success', 'If your email is registered, an e-mail has been sent to ' + emailAddress + ' with further instructions.'); //req.flash('success', 'If your email is registered, an e-mail has been sent to ' + emailAddress + ' with further instructions.');
req.flash('success', 'Wenn Ihre E-Mail-Adresse registriert ist, wurde eine E-Mail mit dem weiteren Vorgehen an ' + emailAddress + ' versendet.'); req.flash('success', 'Wenn Ihre E-Mail-Adresse registriert ist, wurde eine E-Mail mit dem weiteren Vorgehen an ' + emailAddress + ' versendet.');
} }
//res.redirect('/account/forgotPwd'); // deployment //res.redirect('/forgotPwd'); // deployment
res.redirect('/account/forgotPwd'); // localhost res.redirect('/forgotPwd'); // localhost
}); });
}); });
...@@ -418,8 +418,8 @@ module.exports = function (app, config, passport, i18n) { ...@@ -418,8 +418,8 @@ module.exports = function (app, config, passport, i18n) {
if (!user) { if (!user) {
//req.flash('error', 'Password reset token is invalid or has expired.'); //req.flash('error', 'Password reset token is invalid or has expired.');
req.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.'); req.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.');
//res.redirect('/account/forgotPwd'); // deployment //res.redirect('/forgotPwd'); // deployment
res.redirect('/account/forgotPwd'); // localhost res.redirect('/forgotPwd'); // localhost
} }
else { else {
res.render(lang+'/account/reset'); res.render(lang+'/account/reset');
...@@ -428,7 +428,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -428,7 +428,7 @@ module.exports = function (app, config, passport, i18n) {
}); });
app.post('/reset/:token', function(req, res) { app.post('/reset/:token', function(req, res) {
var newPwd = req.body.inputNewPwd var newPwd = req.body.inputNewPwd
methods.getUserByToken(req.params.token, function(err, user){ methods.getUserByToken(req.params.token, function(err, user){
if (user) { if (user) {
// encrypt password // encrypt password
...@@ -458,7 +458,7 @@ module.exports = function (app, config, passport, i18n) { ...@@ -458,7 +458,7 @@ module.exports = function (app, config, passport, i18n) {
} }
}); });
// redirect to login page // redirect to login page
res.redirect('/account/login') res.redirect('/login')
} }
}) })
}); });
...@@ -466,10 +466,10 @@ module.exports = function (app, config, passport, i18n) { ...@@ -466,10 +466,10 @@ module.exports = function (app, config, passport, i18n) {
} }
else { else {
req.flash('error', "User not found.") req.flash('error', "User not found.")
res.redirect('/account/login') res.redirect('/login')
} }
}); });
}); });
// todo: user registration with captcha // todo: user registration with captcha
...@@ -510,9 +510,9 @@ module.exports = function (app, config, passport, i18n) { ...@@ -510,9 +510,9 @@ module.exports = function (app, config, passport, i18n) {
} }
else { else {
//req.flash('success', 'Your account has been created. Please log in.') //req.flash('success', 'Your account has been created. Please log in.')
req.flash('success', 'Ihr Benutzerkonto wurde angelegt. Bitte melden Sie sich an.') req.flash('success', 'Ihr Benutzerkonto wurde angelegt. Bitte melden Sie sich an.')
} }
res.redirect('/account/registration'); res.redirect('/registration');
}) })
}); });
}); });
......
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