‫Alright, now let's very quickly
‫also send emails for password resets,
‫and that email will be very similar to this one,
‫so let's just go ahead and copy all of this
‫into a new file,
‫passwordReset.pug,
‫and then paste that here.
‫Now, some of the text that we want here
‫I believe is already in the authController,
‫so down here in forgotPassword,
‫so right here, actually this message here
‫is kind of what we now want in our template,
‫so let's just grab that, put it here
‫in this first paragraph, now let's put this here
‫at the end of the email,
‫this one we don't need,
‫let's put it here into a separate paragraph,
‫then here, it's actually not this, okay,
‫but instead we use the URL here like this,
‫so an interpolation and then URL,
‫and also, we're actually putting that URL on this,
‫a green button right here.
‫So here, let's then say as a text, reset your password.
‫Then just here, as this paragraph, let's just say for now,
‫Website for this action
‫not yet implemented.
‫So that should be the template,
‫next up, let's actually create the sending function
‫here in our email class, so we have sendWelcome,
‫and now we have another situation
‫for which we want to emails, and so simply enough,
‫we add another method here,
‫so sendPasswordReset,
‫so await this.send,
‫and so now the template name
‫is called passwordReset,
‫so the one that we just created,
‫and now the subject line, which is going to be,
‫Your password reset token,
‫and lets also say, valid for only 10 minutes.
‫Okay, let's save that, and now as a final step,
‫we need to actually call this method here.
‫So in our authController, where before we had
‫all of this here, let's now say, await new Email,
‫just like we did before for the sign up,
‫and now let's find the current user,
‫and it's simply called user, and then the resetURL,
‫that we already defined before up here.
‫Okay, and then the method that we just created,
‫sendPasswordReset, and that's it.
‫Okay, so no defining of subject lines here,
‫also no defining of messages, and so we abstracted
‫all that away with our new, really nice email handler,
‫and let's actually put that one here also in the try block
‫to keep these two here really together.
‫Okay, and so this should be enough
‫that we can now actually test it.
‫Okay, so let's go to Postman, and let's actually
‫reset the password for this user that we just created
‫in the last lecture,
‫so Reset Password,
‫so that's actually not the one,
‫so in fact it is Forgot Password.
‫So here, all we need to specify is the email
‫and that should then get us our reset token, remember?
‫So when I now send this, then we get our success,
‫and so now we should also get our email,
‫and indeed, here it is.
‫So, beautiful!
‫So coming from hello@jonas.io,
‫and going to test3@natours.io
‫which is the user for which we just reset the password,
‫and so here is that URL,
‫and so now let's do the whole flow,
‫and actually really reset the password for this user.
‫So now we need to use the Reset Password route
‫and, well now let's delete all of this,
‫and then also this part, what really matters here
‫is just this token.
‫And now here, let's then set the new password,
‫and let's say actually newpassword,
‫and so that's the one we've been using
‫so that I don't forget it.
‫So let's try that, and with success.
‫Just as a final step, let's see if we
‫can actually log in to our website here.
‫So log in, I think I copied the email,
‫no I did not, so that's test3@natours.io,
‫and what I copied was the password.
‫So that was successful, and we have our default image here,
‫and now of course we could go ahead, upload it,
‫but we already know that that works,
‫and so we don't need to test it.
‫Now, at this point, as you already know,
‫all our emails are actually getting caught here in Mailtrap,
‫and so again, that's because in development mode,
‫we don't want to leak these emails here to real users,
‫also, we would have no way of taking a look at these emails
‫if they would really end up in our real users email inboxes,
‫and so again, that's why we use a service like this.
‫However, in the next video, we will then start to send
‫real emails, so emails to real email addresses,
‫which will then end up in their inboxes.