aboutsummaryrefslogtreecommitdiffstats
path: root/start/events.ts
blob: 11e63e5777896a4336b864cb2d72095a2c57a71d (plain) (blame)
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
import Config from '@ioc:Adonis/Core/Config';
import Event from '@ioc:Adonis/Core/Event';
import Mail from '@ioc:Adonis/Addons/Mail';

/*
|--------------------------------------------------------------------------
| Preloaded File
|--------------------------------------------------------------------------
|
| Any code written inside this file will be executed during the application
| boot.
|
*/
Event.on('forgot::password', async ({ user, token }) => {
  try {
    // eslint-disable-next-line no-console
    console.log('Sending message');
    await Mail.send(message => {
      message
        .subject('[Ferdium] Forgot Password')
        .to(user.email)
        .from(Config.get('dasshboard.mailFrom'))
        .textView('emails.forgot-password', {
          appUrl: Config.get('app.url'),
          username: user.username,
          token,
        });
    });
  } catch (error) {
    // eslint-disable-next-line no-console
    console.log(`Couldn't send mail: ${error}`);
  }
});