diff --git a/routes/routes.js b/routes/routes.js index c55b88e1c380a178c80be47804e5cc591b5c8113..09d5fe6ba430dfd21a27596b4c1eb158db7d078c 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -96,11 +96,15 @@ module.exports = function (app, config, passport, i18n) { text: "" }; - var updatePasswordMailContent = "Hello,\n\n"+ - "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" - + var updatePasswordMailSubject = "Ihr Passwort für das Transferportal wurde gespeichert." + var mailSignature = "Mit den besten Grüßen,\ndas Transferportal-Team der HFT Stuttgart\n\n"+ + "Transferportal der Hochschule für Technik Stuttgart\n"+ + "Schellingstr. 24\n"+ + "70174 Stuttgart\n"+ + "m4lab@hft-stuttgart.de\n"+ + "https://transfer.hft-stuttgart.de" + var updatePasswordMailContent = "Lieber Nutzer,\n\n"+"Ihr Passwort wurde erfolgreich geändert.\n\n"+mailSignature + // ================ test i18n ================== i18n.setLocale('de'); app.get('/de', function(req, res) { @@ -108,30 +112,32 @@ module.exports = function (app, config, passport, i18n) { res.send(greeting) }); + var lang = 'DE' + // ======== APP ROUTES ==================== - app.get('/account', function (req, res) { + app.get('/', function (req, res) { if (req.isAuthenticated()) { methods.getUserByEmail(req.user.email, function(data, err){ if (!err) { - res.render('home', { - greeting: i18n.__('Hello'), + res.render(lang+'/home', { + user: data }); } }) } else { - res.redirect('/account/login'); - } + res.redirect('/login'); // localhost + } }); app.get('/error', function (req, res) { - res.render('error') + res.render(lang+'/error') }); - app.get('/account/login', + app.get('/login', passport.authenticate(config.passport.strategy, { - successRedirect: '/account/', - failureRedirect: '/account/login' + successRedirect: '/', + failureRedirect: '/login' }) ); @@ -157,22 +163,22 @@ module.exports = function (app, config, passport, i18n) { }); }); - app.get('/account/profile', function (req, res) { + app.get('/profile', function (req, res) { if (req.isAuthenticated()) { methods.getUserByEmail(req.user.email, function(data, err){ if (!err) { - res.render('profile', { + res.render(lang+'/profile', { user: data, email: req.user.email }); } }) } else { - res.redirect('/account/login'); + res.redirect('/login'); } }); - app.get('/account/services', function (req, res) { + app.get('/services', function (req, res) { if (req.isAuthenticated()) { async.waterfall([ // get userId by email from userdb @@ -225,29 +231,30 @@ module.exports = function (app, config, passport, i18n) { } // render the page - res.render('services', { + res.render(lang+'/services', { user: req.user, project: allProjects }); } ]) } else { - res.redirect('/account/login'); + res.redirect('/login'); } }); - app.get('/account/security', function (req, res) { + app.get('/security', function (req, res) { if (req.isAuthenticated()) { - res.render('security', { + res.render(lang+'/security', { user: req.user // useful for view engine, useless for HTML }); } else { - res.redirect('/account/login'); + res.redirect('/login'); } }); app.post('/updateProfile', function (req, res) { var userData = { + salutation: req.body.inputSalutation, title: req.body.inputTitle, firstname: req.body.inputFirstname, lastname: req.body.inputLastname, @@ -267,11 +274,11 @@ module.exports = function (app, config, passport, i18n) { else { req.flash('success', 'Profile updated!'); } - res.redirect('/account/profile'); + res.redirect('/profile'); }) } } else { - res.redirect('/account/login'); + res.redirect('/login'); } }); @@ -286,7 +293,7 @@ module.exports = function (app, config, passport, i18n) { // Load hashed passwd from DB dbconn.user.query('SELECT password FROM credential WHERE user_id='+userId, function (err, rows, fields) { if (err) { - res.redirect('/account/500') + res.redirect('/500') throw err } var userPwd = rows[0].password @@ -294,17 +301,21 @@ module.exports = function (app, config, passport, i18n) { // check if the password is correct bcrypt.compare(currPwd, userPwd, function(err, isMatch) { if (err) { - res.redirect('/account/500') + res.redirect('/500') throw err } else if (!isMatch) { - req.flash('error', "Sorry, your password was incorrect. Please double-check your password.") - res.redirect('/account/security') + //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.") + //res.redirect('/account/security') + res.redirect('/security') } else { if ( newPwd != retypePwd ) { + //req.flash('error', "Passwords do no match. Please make sure you re-type your new password correctly.") req.flash('error', "Passwords do no match. Please make sure you re-type your new password correctly.") - res.redirect('/account/security') + //res.redirect('/account/security') + res.redirect('/security') } else { // update password @@ -316,13 +327,16 @@ module.exports = function (app, config, passport, i18n) { } methods.updateCredential(credentialData, function(err){ if (err) { - req.flash('error', "Database error: Password cannot be modified.") + //req.flash('error', "Database error: Password cannot be modified.") + req.flash('error', "Datenbankfehler: Passwort kann nicht geändert werden.") throw err } else { - req.flash('success', "Pasword updated!") + //req.flash('success', "Pasword updated!") + req.flash('success', "Passwort aktualisiert!") mailOptions.to = req.user.email - mailOptions.subject = "Your M4_LAB Password has been updated" + //mailOptions.subject = "Your M4_LAB Password has been updated." + mailOptions.subject = updatePasswordMailSubject mailOptions.text = updatePasswordMailContent smtpTransport.sendMail(mailOptions, function(err) { if (err) { @@ -330,7 +344,8 @@ module.exports = function (app, config, passport, i18n) { } }); } - res.redirect('/account/security') + //res.redirect('/account/security') + res.redirect('/security') }) }); }); @@ -342,12 +357,12 @@ module.exports = function (app, config, passport, i18n) { }) } else { - res.redirect('/account/login'); + res.redirect('/login'); } }); app.get('/forgotPwd', function (req, res) { - res.render('forgotPwd', { + res.render(lang+'/forgotPwd', { user: req.user }); }); @@ -372,13 +387,19 @@ module.exports = function (app, config, passport, i18n) { methods.checkUserEmail(emailAddress, function(err, user){ if (user) { console.log("email: user found"); - var emailSubject = "M4_LAB Password Reset"; - var emailContent = "Hi User,\n\n"+ + //var emailSubject = "M4_LAB Password Reset"; + var emailSubject = "Ihre Passwort-Anfrage an das Transferportal der HFT Stuttgart"; + /* var emailContent = "Hi User,\n\n"+ "we've received a request to reset your password. If you didn't make the request, just ignore this email.\n\n"+ "Otherwise, you can reset your password using this link: http://m4lab.hft-stuttgart.de/account/reset/" + token + "\n" + "This password reset is only valid for 1 hour.\n\n"+ - "Thanks,\nM4_LAB Team" - + "Thanks,\nM4_LAB Team" */ + var emailContent = "Lieber Nutzer,\n\n"+ + "wir haben Ihre Anfrage zur Erneuerung Ihres Passwortes erhalten. Falls Sie diese Anfrage nicht gesendet haben, ignorieren Sie bitte diese E-Mail.\n\n"+ + //"Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: http://m4lab.hft-stuttgart.de/account/reset/" + token + "\n" + // test server + "Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: http://localhost:9989/reset/" + token + "\n" + // localhost + "Dieser Link ist aus Sicherheitsgründen nur für 1 Stunde gültig.\n\n"+mailSignature + var credentialData = { user_id: user.id, resetPasswordToken: token, @@ -402,34 +423,30 @@ module.exports = function (app, config, passport, i18n) { } }); } - /*, - function(token, user, done) { - mailOptions.to = emailAddress; - mailOptions.subject = emailSubject; - mailOptions.text = emailContent; - smtpTransport.sendMail(mailOptions, function(err) { - done(err, 'done'); - }); - } */ ], function(err) { if (err) { - req.flash('error', 'An error occured. Please try again.'); + //req.flash('error', 'An error occured. Please try again.'); + req.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.'); } else { - 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.'); } - res.redirect('/account/forgotPwd'); + //res.redirect('/account/forgotPwd'); // deployment + res.redirect('/forgotPwd'); // localhost }); }); app.get('/reset/:token', function(req, res) { methods.getUserByToken(req.params.token, function(err, user){ if (!user) { - req.flash('error', 'Password reset token is invalid or has expired.'); - res.redirect('/account/forgotPwd'); + //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.'); + //res.redirect('/account/forgotPwd'); // deployment + res.redirect('/forgotPwd'); // localhost } else { - res.render('reset'); + res.render(lang+'/reset'); } }); }); @@ -448,11 +465,13 @@ module.exports = function (app, config, passport, i18n) { // update password methods.updateCredential(credentialData, function(err){ if (err) { - req.flash('error', "Database error: Password cannot be modified.") + //req.flash('error', "Database error: Password cannot be modified.") + req.flash('error', "Datenbankfehler: Passwort kann nicht geändert werden.") throw err } else { - req.flash('success', "Your pasword has been updated.") + //req.flash('success', "Your pasword has been updated.") + req.flash('success', "Passwort aktualisiert!") // send notifiaction email mailOptions.to = user.email mailOptions.subject = updatePasswordMailSubject @@ -463,7 +482,7 @@ module.exports = function (app, config, passport, i18n) { } }); // redirect to login page - res.redirect('/account/login') + res.redirect('/login') } }) }); @@ -471,7 +490,7 @@ module.exports = function (app, config, passport, i18n) { } else { req.flash('error', "User not found.") - res.redirect('/account/login') + res.redirect('/login') } }); @@ -479,7 +498,7 @@ module.exports = function (app, config, passport, i18n) { // todo: user registration with captcha app.get('/registration', function(req, res) { - res.render('registration') + res.render(lang+'/registration') }) app.post('/registration', function(req, res) { @@ -490,6 +509,7 @@ module.exports = function (app, config, passport, i18n) { // user data var curDate = new Date() var userData = { + salutation: req.body.inputSalutation, title: req.body.inputTitle, firstname: req.body.inputFirstname, lastname: req.body.inputLastname, @@ -509,12 +529,15 @@ module.exports = function (app, config, passport, i18n) { } methods.registerNewUser(newAccount, function(err){ if (err) { - req.flash('error', "Failed"); + //req.flash('error', "Failed") + req.flash('error', "Fehlgeschlagen") } 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.') } - res.redirect('/account/registration'); + //res.redirect('/account/registration'); // deployment + res.redirect('/registration'); // localhost }) }); }); diff --git a/views/DE/home.pug b/views/DE/home.pug index 53044de199cab276dc2e016841b22f1c76d66173..58b2427c3063a835f93a8be4ad87515929121978 100644 --- a/views/DE/home.pug +++ b/views/DE/home.pug @@ -34,9 +34,9 @@ html(lang="de") h5 span #{user.firstname} #{user.lastname} div(class="nav flex-column nav-pills", id="v-pills-tab", role="tablist", aria-orientation="vertical") - a(class="nav-link" href="#" aria-selected="true") Benutzerprofil - a(class="nav-link" href="/account/security" aria-selected="false") Sicherheitseinstellungen - a(class="nav-link" href="/account/services" aria-selected="false") Projekte und Dienste + a(class="nav-link" href="/profile" aria-selected="true") Benutzerprofil + a(class="nav-link" href="/security" aria-selected="false") Sicherheitseinstellungen + a(class="nav-link" href="/services" aria-selected="false") Projekte und Dienste div(class="col-sm-9") p content goes here diff --git a/views/DE/profile.pug b/views/DE/profile.pug index 9a3fc46ed51515e72e4d5c29c2ed1faecbde3ef5..32a2aff116c487f82b6c6b2bd6d50637c5cedd2f 100644 --- a/views/DE/profile.pug +++ b/views/DE/profile.pug @@ -35,8 +35,8 @@ html(lang="de") span #{user.firstname} #{user.lastname} div(class="nav flex-column nav-pills", id="v-pills-tab", role="tablist", aria-orientation="vertical") a(class="nav-link" href="#" aria-selected="true") Benutzerprofil - a(class="nav-link" href="/account/security" aria-selected="false") Sicherheitseinstellungen - a(class="nav-link" href="/account/services" aria-selected="false") Projekte und Dienste + a(class="nav-link" href="/security" aria-selected="false") Sicherheitseinstellungen + a(class="nav-link" href="/services" aria-selected="false") Projekte und Dienste div(class="col-sm-9") if successes for success in successes @@ -48,9 +48,23 @@ html(lang="de") a(class="close", href="#", data-dismiss="alert", aria-label="close") × form#profileForm(method="POST", action="/updateProfile") div(class="form-row") + div(class='form-group col-md-2') + label(for="title") Anrede + select#inputSalutation(name="inputSalutation", class="form-control", , value=user.salutation) + option(value="") - Anrede - + option(value="Herr") Herr + option(value="Frau") Frau + option(value="Divers") Divers + script. + var salutationOptions = document.getElementById('inputSalutation').options; + for (i=0; i < salutationOptions.length; i++) { + if (salutationOptions[i].value == '#{user.salutation}') + salutationOptions[i].selected = true; + } div(class='form-group col-md-2') label(for="title") Titel select#inputTitle(name="inputTitle", class="form-control", value=user.title) + option(value="") - Titel - option(value="Prof.") Prof. option(value="Dr.") Dr. option(value="Dipl.-Ing.") Dipl.-Ing. @@ -61,15 +75,15 @@ html(lang="de") if (titleOptions[i].value == '#{user.title}') titleOptions[i].selected = true; } - div(class='form-group col-md-3') + div(class='form-group col-md-2') label(for="firstname") Vorname input#inputFirstname(name="inputFirstname", type="text", class="form-control", placeholder="Vorname", value=user.firstname required) - div(class='form-group col-md-3') + div(class='form-group col-md-2') label(for="lastname") Nachname input#inputLastname(name="inputLastname", type="text", class="form-control", placeholder="Nachname", value=user.lastname required) div(class="form-row") div(class='form-group col-md-8') - label(for="email") Email + label(for="email") E-mail Adresse input#inputEmail(name="inputEmail", type="email", class="form-control", placeholder="Email", value=email required) div(class="form-row") div(class='form-group col-md-8') @@ -83,7 +97,7 @@ html(lang="de") div(class='form-group col-md-8') label(for="speciality") Fachgebiete input#inputSpeciality(name="inputSpeciality", type="text", class="form-control", placeholder="Fachgebiete", value=user.speciality) - input(type="submit", class="btn btn-primary", value="Update") + input(type="submit", class="btn btn-primary", value="Speichern") // jQuery script(src="https://code.jquery.com/jquery-3.3.1.min.js") diff --git a/views/DE/registration.pug b/views/DE/registration.pug index f5e9973e2e4ccbaac94d2dc819d22c88e9d4b4e4..ab1c7e5a74c6a425f0dc151fff824d79a15ff5ae 100644 --- a/views/DE/registration.pug +++ b/views/DE/registration.pug @@ -82,7 +82,7 @@ html(lang="de") p <em><small>* Pflichtfeld</small></em> input#submitBtn(type="submit", class="btn btn-outline-dark btn-block", value="Senden" disabled) br - p(class="text-center") Sie haben bereits ein Benutzerkonto? <a href="/account">Melden Sie sich hier an</a>. + p(class="text-center") Sie haben bereits ein Benutzerkonto? <a href="/login">Melden Sie sich hier an</a>. // jQuery diff --git a/views/DE/security.pug b/views/DE/security.pug index 5d4a214af3e689f94fb986ebf5f466930560f331..560d32bc554c360f2cc32783f4aeda33b546d0fe 100644 --- a/views/DE/security.pug +++ b/views/DE/security.pug @@ -37,9 +37,9 @@ html(lang="de") h5 span #{user.firstName} #{user.lastName} div(class="nav flex-column nav-pills", id="v-pills-tab", role="tablist", aria-orientation="vertical") - a(class="nav-link" href="/account/profile" aria-selected="true") Benutzerprofil + a(class="nav-link" href="/profile" aria-selected="true") Benutzerprofil a(class="nav-link" href="#" aria-selected="false") Sicherheitseinstellungen - a(class="nav-link" href="/account/services" aria-selected="false") Projekte und Dienste + a(class="nav-link" href="/services" aria-selected="false") Projekte und Dienste div(class="col-sm-9") if successes for success in successes @@ -53,18 +53,18 @@ html(lang="de") div(class="form-group row") label(for="currPwd") Aktuelles Passwort input(id="inputCurrPwd", name="inputCurrPwd", type="password", class="form-control" required) - div(class="invalid-feedback") Please fill in this field. + div(class="invalid-feedback") Bitte füllen Sie dieses Feld aus. div(class="form-group row") label(for="newPwd") Neues Passwort input#inputNewPwd(name="inputNewPwd", type="password", class="form-control" required) span#recommendation - div(class="invalid-feedback") Please fill in this field. + div(class="invalid-feedback") Bitte füllen Sie dieses Feld aus. div(class="form-group row") label(for="confirm") Bestätigen Sie das neue Passwort input#inputConfirm(name="inputConfirm", type="password", class="form-control" required) span#message - div(class="invalid-feedback") Please fill in this field. - input#updateBtn(type="submit", class="btn btn-primary", value="Update Password" disabled) + div(class="invalid-feedback") Bitte füllen Sie dieses Feld aus. + input#updateBtn(type="submit", class="btn btn-primary", value="Passwort ändern" disabled) // jQuery script(src="https://code.jquery.com/jquery-3.3.1.min.js") diff --git a/views/DE/services.pug b/views/DE/services.pug index 6ab101f30c8da9f6c5b53d526af7c4dd8178936b..55f5a1b66458fb86a0bd9a6e2069da57a4d370ea 100644 --- a/views/DE/services.pug +++ b/views/DE/services.pug @@ -34,8 +34,8 @@ html(lang="de") h5 span #{user.firstName} #{user.lastName} div(class="nav flex-column nav-pills", id="v-pills-tab", role="tablist", aria-orientation="vertical") - a(class="nav-link" href="/account/profile" aria-selected="true") Benutzerprofil - a(class="nav-link" href="/account/security" aria-selected="false") Sicherheitseinstellungen + a(class="nav-link" href="/profile" aria-selected="true") Benutzerprofil + a(class="nav-link" href="/security" aria-selected="false") Sicherheitseinstellungen a(class="nav-link" href="#" aria-selected="false") Projekte und Dienste div(class="col-sm-9") if successes