Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,070 --> 00:00:03,190
Alright, now let's very quickly
2
00:00:03,190 --> 00:00:06,403
also send emails for password resets,
3
00:00:08,060 --> 00:00:11,070
and that email will be very similar to this one,
4
00:00:11,070 --> 00:00:13,800
so let's just go ahead and copy all of this
5
00:00:14,830 --> 00:00:16,393
into a new file,
6
00:00:18,267 --> 00:00:21,343
passwordReset.pug,
7
00:00:24,410 --> 00:00:25,983
and then paste that here.
8
00:00:28,460 --> 00:00:30,780
Now, some of the text that we want here
9
00:00:30,780 --> 00:00:33,293
I believe is already in the authController,
10
00:00:34,690 --> 00:00:38,073
so down here in forgotPassword,
11
00:00:39,850 --> 00:00:41,960
so right here, actually this message here
12
00:00:41,960 --> 00:00:44,793
is kind of what we now want in our template,
13
00:00:46,640 --> 00:00:50,610
so let's just grab that, put it here
14
00:00:50,610 --> 00:00:55,470
in this first paragraph, now let's put this here
15
00:00:55,470 --> 00:00:56,883
at the end of the email,
16
00:00:59,290 --> 00:01:00,840
this one we don't need,
17
00:01:00,840 --> 00:01:03,040
let's put it here into a separate paragraph,
18
00:01:04,800 --> 00:01:09,290
then here, it's actually not this, okay,
19
00:01:09,290 --> 00:01:12,250
but instead we use the URL here like this,
20
00:01:12,250 --> 00:01:16,370
so an interpolation and then URL,
21
00:01:16,370 --> 00:01:19,910
and also, we're actually putting that URL on this,
22
00:01:19,910 --> 00:01:22,053
a green button right here.
23
00:01:22,970 --> 00:01:27,970
So here, let's then say as a text, reset your password.
24
00:01:32,830 --> 00:01:37,643
Then just here, as this paragraph, let's just say for now,
25
00:01:38,560 --> 00:01:41,800
Website for this action
26
00:01:45,730 --> 00:01:47,193
not yet implemented.
27
00:01:50,577 --> 00:01:53,280
So that should be the template,
28
00:01:53,280 --> 00:01:56,360
next up, let's actually create the sending function
29
00:01:56,360 --> 00:02:01,360
here in our email class, so we have sendWelcome,
30
00:02:01,490 --> 00:02:03,130
and now we have another situation
31
00:02:03,130 --> 00:02:07,100
for which we want to emails, and so simply enough,
32
00:02:07,100 --> 00:02:09,300
we add another method here,
33
00:02:09,300 --> 00:02:11,193
so sendPasswordReset,
34
00:02:18,260 --> 00:02:22,640
so await this.send,
35
00:02:22,640 --> 00:02:24,590
and so now the template name
36
00:02:24,590 --> 00:02:28,630
is called passwordReset,
37
00:02:28,630 --> 00:02:31,290
so the one that we just created,
38
00:02:31,290 --> 00:02:34,683
and now the subject line, which is going to be,
39
00:02:36,480 --> 00:02:40,610
Your password reset token,
40
00:02:40,610 --> 00:02:45,610
and lets also say, valid for only 10 minutes.
41
00:02:49,740 --> 00:02:54,060
Okay, let's save that, and now as a final step,
42
00:02:54,060 --> 00:02:56,713
we need to actually call this method here.
43
00:02:58,577 --> 00:03:01,540
So in our authController, where before we had
44
00:03:01,540 --> 00:03:06,540
all of this here, let's now say, await new Email,
45
00:03:08,980 --> 00:03:11,580
just like we did before for the sign up,
46
00:03:11,580 --> 00:03:13,873
and now let's find the current user,
47
00:03:14,860 --> 00:03:19,263
and it's simply called user, and then the resetURL,
48
00:03:20,400 --> 00:03:23,243
that we already defined before up here.
49
00:03:25,641 --> 00:03:28,470
Okay, and then the method that we just created,
50
00:03:28,470 --> 00:03:32,483
sendPasswordReset, and that's it.
51
00:03:33,860 --> 00:03:37,740
Okay, so no defining of subject lines here,
52
00:03:37,740 --> 00:03:42,660
also no defining of messages, and so we abstracted
53
00:03:42,660 --> 00:03:47,033
all that away with our new, really nice email handler,
54
00:03:48,597 --> 00:03:51,970
and let's actually put that one here also in the try block
55
00:03:51,970 --> 00:03:53,920
to keep these two here really together.
56
00:03:56,680 --> 00:03:59,360
Okay, and so this should be enough
57
00:03:59,360 --> 00:04:01,183
that we can now actually test it.
58
00:04:03,260 --> 00:04:08,260
Okay, so let's go to Postman, and let's actually
59
00:04:08,270 --> 00:04:11,670
reset the password for this user that we just created
60
00:04:11,670 --> 00:04:12,833
in the last lecture,
61
00:04:15,070 --> 00:04:17,202
so Reset Password,
62
00:04:18,390 --> 00:04:21,100
so that's actually not the one,
63
00:04:21,100 --> 00:04:23,803
so in fact it is Forgot Password.
64
00:04:25,280 --> 00:04:28,920
So here, all we need to specify is the email
65
00:04:28,920 --> 00:04:33,300
and that should then get us our reset token, remember?
66
00:04:33,300 --> 00:04:38,300
So when I now send this, then we get our success,
67
00:04:38,350 --> 00:04:41,350
and so now we should also get our email,
68
00:04:41,350 --> 00:04:43,223
and indeed, here it is.
69
00:04:44,970 --> 00:04:47,080
So, beautiful!
70
00:04:47,080 --> 00:04:49,940
So coming from hello@jonas.io,
71
00:04:49,940 --> 00:04:53,670
and going to test3@natours.io
72
00:04:53,670 --> 00:04:57,540
which is the user for which we just reset the password,
73
00:04:57,540 --> 00:04:59,453
and so here is that URL,
74
00:05:00,540 --> 00:05:03,290
and so now let's do the whole flow,
75
00:05:03,290 --> 00:05:06,583
and actually really reset the password for this user.
76
00:05:08,090 --> 00:05:12,520
So now we need to use the Reset Password route
77
00:05:14,100 --> 00:05:18,857
and, well now let's delete all of this,
78
00:05:21,690 --> 00:05:25,700
and then also this part, what really matters here
79
00:05:25,700 --> 00:05:27,163
is just this token.
80
00:05:29,349 --> 00:05:32,760
And now here, let's then set the new password,
81
00:05:32,760 --> 00:05:35,603
and let's say actually newpassword,
82
00:05:37,660 --> 00:05:40,530
and so that's the one we've been using
83
00:05:40,530 --> 00:05:41,830
so that I don't forget it.
84
00:05:43,790 --> 00:05:47,053
So let's try that, and with success.
85
00:05:49,280 --> 00:05:51,190
Just as a final step, let's see if we
86
00:05:51,190 --> 00:05:54,283
can actually log in to our website here.
87
00:05:57,590 --> 00:06:00,123
So log in, I think I copied the email,
88
00:06:01,080 --> 00:06:05,180
no I did not, so that's test3@natours.io,
89
00:06:10,300 --> 00:06:12,050
and what I copied was the password.
90
00:06:14,370 --> 00:06:18,737
So that was successful, and we have our default image here,
91
00:06:18,737 --> 00:06:21,650
and now of course we could go ahead, upload it,
92
00:06:21,650 --> 00:06:24,350
but we already know that that works,
93
00:06:24,350 --> 00:06:26,340
and so we don't need to test it.
94
00:06:26,340 --> 00:06:29,120
Now, at this point, as you already know,
95
00:06:29,120 --> 00:06:32,870
all our emails are actually getting caught here in Mailtrap,
96
00:06:32,870 --> 00:06:35,980
and so again, that's because in development mode,
97
00:06:35,980 --> 00:06:39,433
we don't want to leak these emails here to real users,
98
00:06:40,640 --> 00:06:44,530
also, we would have no way of taking a look at these emails
99
00:06:44,530 --> 00:06:48,093
if they would really end up in our real users email inboxes,
100
00:06:49,280 --> 00:06:53,050
and so again, that's why we use a service like this.
101
00:06:53,050 --> 00:06:55,820
However, in the next video, we will then start to send
102
00:06:55,820 --> 00:06:59,620
real emails, so emails to real email addresses,
103
00:06:59,620 --> 00:07:02,263
which will then end up in their inboxes.
8039
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.