Commit 354419d8 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

MLAB 249: Prevent HFT accounts to create an account from the registration page.

parent c0b0a64e
This commit is part of merge request !39. Comments created here will be created in the context of that merge request.
Showing with 69 additions and 55 deletions
+69 -55
...@@ -523,60 +523,71 @@ module.exports = function (app, config, passport, i18n) { ...@@ -523,60 +523,71 @@ module.exports = function (app, config, passport, i18n) {
createdDate: curDate.toISOString().slice(0,10) createdDate: curDate.toISOString().slice(0,10)
} }
let token var userEmail = userData.email
async.waterfall([ var pos = userEmail.indexOf('@')
function(done) { var emailLength = userEmail.length
crypto.randomBytes(20, function(err, buf) { var emailDomain = userEmail.slice(pos, emailLength);
token = buf.toString('hex');
done(err, token); if ( emailDomain.toLowerCase() == "@hft-stuttgart.de") {
}); req.flash('error', "Fehlgeschlagen: HFT-Account")
}, res.redirect('/account/registration');
// encrypt password }
function(token, done) { else {
bcrypt.genSalt(saltRounds, function(err, salt) { let token
bcrypt.hash(req.body.inputPassword, salt, function(err, hash) { async.waterfall([
var newAccount = { function(done) {
profile: userData, crypto.randomBytes(20, function(err, buf) {
password: hash, token = buf.toString('hex');
verificationToken: token done(err, token);
}
done(err, newAccount)
}); });
}); },
}, // encrypt password
// save data function(token, done) {
function(newAccount, err) { bcrypt.genSalt(saltRounds, function(err, salt) {
methods.registerNewUser(newAccount, function(err){ bcrypt.hash(req.body.inputPassword, salt, function(err, hash) {
if (err) { var newAccount = {
req.flash('error', "Fehlgeschlagen") profile: userData,
} password: hash,
else { verificationToken: token
// send email
var emailSubject = "Bitte bestätigen Sie Ihr M4_LAB Benutzerkonto"
var emailContent = "Lieber Nutzer,\n\n"+
"vielen Dank für Ihre Anmeldung am Transferportal der HFT Stuttgart.\n"+
"Um Ihre Anmeldung zu bestätigen, klicken Sie bitte diesen Link: "+config.app.host+"/verifyAccount?token="+token+"\n"+
"Ohne Bestätigung Ihres Kontos müssen wir Ihr Konto leider nach 7 Tagen löschen.\n\n"+
"Sollten Sie sich selbst nicht mit Ihren Daten am Transferportal registriert haben, ignorieren Sie diese E-Mail bitte.\n\n"+mailSignature
mailer.options.to = req.body.inputEmail;
mailer.options.subject = emailSubject;
mailer.options.text = emailContent;
mailer.transport.sendMail(mailer.options, function(err) {
if (err) {
console.log('cannot send email')
throw err
} }
}) done(err, newAccount)
// user feedback });
req.flash('success', 'Vielen Dank für Ihre Registrierung!'+'\r\n\r\n'+ });
'Wir haben Ihnen eine E-Mail an Ihre verwendete Adresse gesendet. Diese enthält einen Link zur Bestätigung Ihres Accounts.'+'\r\n'+ },
'Wenn Sie die Mail nicht in ihrem Postfach vorfinden, prüfen Sie bitte auch Ihren Spam-Ordner.') // save data
} function(newAccount, err) {
res.redirect('/account/registration') methods.registerNewUser(newAccount, function(err){
}) if (err) {
} req.flash('error', "Fehlgeschlagen")
]) }
else {
// send email
var emailSubject = "Bitte bestätigen Sie Ihr M4_LAB Benutzerkonto"
var emailContent = "Lieber Nutzer,\n\n"+
"vielen Dank für Ihre Anmeldung am Transferportal der HFT Stuttgart.\n"+
"Um Ihre Anmeldung zu bestätigen, klicken Sie bitte diesen Link: "+config.app.host+"/verifyAccount?token="+token+"\n"+
"Ohne Bestätigung Ihres Kontos müssen wir Ihr Konto leider nach 7 Tagen löschen.\n\n"+
"Sollten Sie sich selbst nicht mit Ihren Daten am Transferportal registriert haben, ignorieren Sie diese E-Mail bitte.\n\n"+mailSignature
mailer.options.to = req.body.inputEmail;
mailer.options.subject = emailSubject;
mailer.options.text = emailContent;
mailer.transport.sendMail(mailer.options, function(err) {
if (err) {
console.log('cannot send email')
throw err
}
})
// user feedback
req.flash('success', 'Vielen Dank für Ihre Registrierung!'+'\r\n\r\n'+
'Wir haben Ihnen eine E-Mail an Ihre verwendete Adresse gesendet. Diese enthält einen Link zur Bestätigung Ihres Accounts.'+'\r\n'+
'Wenn Sie die Mail nicht in ihrem Postfach vorfinden, prüfen Sie bitte auch Ihren Spam-Ordner.')
}
res.redirect('/account/registration')
})
}
])
}
}) })
// ============= USER VERIFICATION ================================ // ============= USER VERIFICATION ================================
......
...@@ -14,9 +14,12 @@ html(lang="de") ...@@ -14,9 +14,12 @@ html(lang="de")
body body
div(class="container-fluid") div(class="container-fluid")
div(class="row") div(class="row")
div(class="col-md-6 offset-md-2") div(class="pt-4 pb-4 col-md-6 offset-md-2")
h3(class="mb-3 font-weight-bold") Neues Benutzerkonto anlegen h3(class="mb-3 font-weight-bold") Neues Benutzerkonto anlegen
div(class="col-md-6 offset-md-3") div(class="col-md-6 offset-md-3")
div(class="alert alert-info" role="alert")
| Auf dieser Seite können sich Benutzer, die keinen Account an der HFT haben, registrieren.<br/>
| Um sich mit ihrem HFT-Account anzumelden, klicken Sie <a class="font-weight-bold" href="https://transfer.hft-stuttgart.de/account/">hier</a>.
if successes if successes
for success in successes for success in successes
div.alert.alert-success.alert-dismissible #{ success } div.alert.alert-success.alert-dismissible #{ success }
...@@ -26,7 +29,7 @@ html(lang="de") ...@@ -26,7 +29,7 @@ html(lang="de")
div.alert.alert-danger.alert-dismissible.fade.show #{ error } div.alert.alert-danger.alert-dismissible.fade.show #{ error }
a(class="close", href="#", data-dismiss="alert", aria-label="close") &times; a(class="close", href="#", data-dismiss="alert", aria-label="close") &times;
form(method="POST") form(method="POST")
h5(class="mb-3 font-weight-bold") Anmeldedaten h5(class="pt-2 mb-3 font-weight-bold") Anmeldedaten
div(class='form-row') div(class='form-row')
div(class='form-group col-md-6') div(class='form-group col-md-6')
input#inputEmail(name="inputEmail", type="email", class="form-control", placeholder="E-Mail-Adresse*", maxlength="45" required) input#inputEmail(name="inputEmail", type="email", class="form-control", placeholder="E-Mail-Adresse*", maxlength="45" required)
...@@ -34,7 +37,7 @@ html(lang="de") ...@@ -34,7 +37,7 @@ html(lang="de")
div(class="form-group col-md-6") div(class="form-group col-md-6")
input#inputPassword(name="inputPassword", type="password", class="form-control", data-toggle="password", placeholder="Passwort*", maxlength="45" required) input#inputPassword(name="inputPassword", type="password", class="form-control", data-toggle="password", placeholder="Passwort*", maxlength="45" required)
span#passwordWarning(class='warning') span#passwordWarning(class='warning')
h5(class="mb-3 font-weight-bold") Benutzerprofil h5(class="pt-2 mb-3 font-weight-bold") Benutzerprofil
div(class="form-row") div(class="form-row")
div(class='form-group col-md-2') div(class='form-group col-md-2')
select#inputSalutation(name="inputSalutation", class="form-control") select#inputSalutation(name="inputSalutation", class="form-control")
......
Supports Markdown
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