import async from 'async' import mailer from '../config/mailer' import { dbController } from './dbController' const lang = 'DE' const publicController = { showRegistrationPage: function (res: any) { res.render(lang + '/account/registration') }, showContactPage: function (req: any, res: any) { res.render(lang + '/account/contact', { user: req.user }) }, showForgotPwdPage: function (req: any, res: any) { res.render(lang + '/account/forgotPwd', { user: req.user }) }, showResetToken: async function (req: any, res: any) { const user = await dbController.getUserByToken(req.params.token) if (user) { res.render(lang + '/account/reset') } else { res.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.') res.redirect('/account/forgotPwd') } }, sendContactMessage: function (req: any, res: any) { const emailAddress = req.body.inputEmail const supportAddress = 'support-transfer@hft-stuttgart.de' const inputName = req.body.name const inputContent = req.body.message const emailSubject = 'Ihre Anfrage an das Transferportal' const emailContent = '
Es wurde eine Anfrage an das Transferportal gestellt:

NAME: ' + inputName + '
NACHRICHT: ' + inputContent + '
' async.waterfall([ function (done: any) { // send email mailer.options.to = supportAddress mailer.options.cc = emailAddress mailer.options.subject = emailSubject mailer.options.html = emailContent mailer.transporter.sendMail(mailer.options, function (err: any) { done(err, 'done') }) } ], function (err: any) { if (!err) { res.flash('success', 'Vielen Dank für Ihre Anfrage. Wir melden uns baldmöglichst bei Ihnen. Eine Kopie Ihrer Anfrage wurde an ' + emailAddress + ' versandt.') } else { console.error(err) res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.') } res.redirect('/account/contact') }) }, checkUserEmail: async function (req: any, res: any) { const user = await dbController.checkUserEmail(req.params.email) if (user) { res.send(false) } else { res.send(true) } } } export { publicController }