publicController.ts 2.27 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 = '<div>Es wurde eine Anfrage an das Transferportal gestellt: <br/><br/>NAME: ' + inputName + '<br/>NACHRICHT: ' + inputContent + '</div>'
    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 }