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