Python for Entrepreneurs Transcripts
Chapter: Sending and receiving email
Lecture: Demo: Setting up password resets
Login or
purchase this course
to watch this video and the rest of the course contents.
0:02
Let's return to our account controller. Now, there is actually a bunch of small fiddly work that you have to do
0:10
to get the password reset process in place, there is three different views, let's go in our templates and I'll show you.
0:18
So first of all, you need to update the sign in process, so next to the sign in,
0:24
you could say something like "here is the login information... email, password, login",
0:29
and then "Oh, did you forget your login? Click here to reset it." So then, that will take us over to this forgot_password view,
0:35
this will let you enter your email address and say "I would like to reset my password",
0:39
which will trigger the creation of a password reset in the database, and send you an email with that information that you can use.
0:46
Then we also want to tell you "hey, we sent that to you correctly", so we have a reset_sent view, we could have just added that as a view
0:57
to the forgot_password form and shown it only after it was submitted, but it's just about as easy to have to views as it is
1:04
to have the conditional logic to make that happen. So we have this, and then finally there is a link that the person gets
1:10
in their email address, when they get in their email address, they are going to click it and it is going to take them to a form, here,
1:16
where they can actually enter their new password and it will reset it and then they can go log in. So, I went and put those forms together for you,
1:24
there is nothing fancy, they are just like the log in forms and so on, but there is no use in you watching me do that, right,
1:30
you've done these forms over and over, so it's all good, you can review the code if you want and you'll see it in the demo.
1:36
Now at the bottom of the account controller I added the corresponding action methods,
1:40
and the view models, OK, so here is the forgot_password form, right, this tells you what it does, we've got the GET / POST /Redirect pattern,
1:49
we are not redirecting yet, we will, it's got the ForgotPassWordViewModel
1:54
that has a few pieces of information like what is your email address and things like that.
1:58
Then of course we have the basic reset_sent and then we have the form to do the actual reset itself.
2:05
OK. But, notice, these don't really do anything, other than just hold the data.
2:09
So our job will be to create the table in the database so it manages the reset password, set up the code to do the resets and send the emails.
2:18
Oh yes, and over in the email section here, we now have a template for password reset, here,
2:24
and let's just view this in the browser, here you can see this is a basic-looking one,
2:30
this is just one of those template emails we already talked about, so we heard about your password at Blue / Yellow rockets, remember,
2:38
this is an image and I haven't changed it, we are just going to go with that image for now.
2:43
If you click this button to reset it, it's going to take you to this URL which is where things are running.
2:49
And then it's going to say account/reset_password and then we are going to replace the reset code
2:54
with whatever the reset code that we generate for them is. Alright, so that's the plan, let's put it into action.