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


Talk Python's Mastodon Michael Kennedy's Mastodon