Python for Entrepreneurs Transcripts
Chapter: User accounts and identity
Lecture: A peek inside Talk Python accounts

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Now throughput this class I've tried to give you a look inside the real businesses
0:05 the real code that runs in production,
0:08 for Talk Python the podcast or the Training website, and things like that.
0:12 So, let's take a quick look at how account management works in Talk Python Training.
0:17 And I come over and I say I would like to register,
0:20 I am going to fill out the username and email, like I showed you in the example,
0:23 I prefer to just drop this username and just have email but whatever.
0:27 Username, email, password and confirm password, we'll hit go
0:30 and then of course password is required
0:32 but it would take us through the registration process,
0:34 you've all been through this process, so let's go over here and notice,
0:38 we have a GET / POST / Redirect pattern again.
0:41 We are doing basic stuff, we are actually checking to see
0:44 if the user is logged in, we'll get to this part later,
0:47 when we talk about how to manage this inner app,
0:49 but if they are logged in then don't let them try
0:51 to log in again, just take them to their account.
0:54 This is unlikely, but maybe they type training.talkpython.fm in their browser
0:59 and it remembers the registration page first or whatever.
1:03 OK so that is basic and then, here is the thing that actually does the work,
1:07 we have our view model just like I showed you,
1:10 it's going to verify things like "hey, the password is required, don't mess around",
1:13 and we never touch the database for this.
1:15 Then we are going to come down and we do a few more checks,
1:18 because you can log in both by username or email, we do checks for each,
1:24 if you try to create an account with that username it says:
1:25 "Hey this is already taken, do you need the login instead?"
1:27 "Hey that email is taken, do you need to login instead?"
1:30 And then we have an account_create... username, email, password
1:35 and we're explicitly setting whether or not you are an admin to be False,
1:38 and then, we are going to talk about this later, about
1:41 storing your authentication your, login and a cookie, we send a "welcome" email,
1:46 we add you to the MailChimp mailing list that we have talked about;
1:51 we have the ability to indicate like "hey, go log in
1:54 and when you're done go back to this other place", like if I send an email
1:56 to somebody and say "hey, thanks for buying this course,
2:00 go log in and then you'll have access to it", well, that log,
2:03 that final redirect might be where I want to send them is the course
2:06 not to their account page but if nothing, no one is there then we get this,
2:09 now if we look at the AccountService, here is our create_account,
2:13 so we have more login and whatnot, we'll talk about that later,
2:17 we have a little bit stronger checking here to make sure that the data is valid,
2:21 and I have this little context manager that I use for managing database sessions,
2:28 the unit of work, but here we go, we are creating an account or setting the hash password
2:34 or adding it we are logging in, and then we get it back from the database again
2:38 there is a couple of reasons I did this but it is not really worth going into,
2:42 I just want to make sure I get the actual thing I put in the database back out here.
2:46 So that's a peek inside Talk Python Training,
2:49 it should look pretty familiar to what we just saw in our demo.