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
......@@ -523,60 +523,71 @@ module.exports = function (app, config, passport, i18n) {
createdDate: curDate.toISOString().slice(0,10)
}
let token
async.waterfall([
function(done) {
crypto.randomBytes(20, function(err, buf) {
token = buf.toString('hex');
done(err, token);
});
},
// encrypt password
function(token, done) {
bcrypt.genSalt(saltRounds, function(err, salt) {
bcrypt.hash(req.body.inputPassword, salt, function(err, hash) {
var newAccount = {
profile: userData,
password: hash,
verificationToken: token
}
done(err, newAccount)
var userEmail = userData.email
var pos = userEmail.indexOf('@')
var emailLength = userEmail.length
var emailDomain = userEmail.slice(pos, emailLength);
if ( emailDomain.toLowerCase() == "@hft-stuttgart.de") {
req.flash('error', "Fehlgeschlagen: HFT-Account")
res.redirect('/account/registration');
}
else {
let token
async.waterfall([
function(done) {
crypto.randomBytes(20, function(err, buf) {
token = buf.toString('hex');
done(err, token);
});
});
},
// save data
function(newAccount, err) {
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
},
// encrypt password
function(token, done) {
bcrypt.genSalt(saltRounds, function(err, salt) {
bcrypt.hash(req.body.inputPassword, salt, function(err, hash) {
var newAccount = {
profile: userData,
password: hash,
verificationToken: token
}
})
// 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')
})
}
])
done(err, newAccount)
});
});
},
// save data
function(newAccount, err) {
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 ================================
......
......@@ -14,9 +14,12 @@ html(lang="de")
body
div(class="container-fluid")
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
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
for success in successes
div.alert.alert-success.alert-dismissible #{ success }
......@@ -26,7 +29,7 @@ html(lang="de")
div.alert.alert-danger.alert-dismissible.fade.show #{ error }
a(class="close", href="#", data-dismiss="alert", aria-label="close") &times;
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-group col-md-6')
input#inputEmail(name="inputEmail", type="email", class="form-control", placeholder="E-Mail-Adresse*", maxlength="45" required)
......@@ -34,7 +37,7 @@ html(lang="de")
div(class="form-group col-md-6")
input#inputPassword(name="inputPassword", type="password", class="form-control", data-toggle="password", placeholder="Passwort*", maxlength="45" required)
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-group col-md-2')
select#inputSalutation(name="inputSalutation", class="form-control")
......
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