Full Web Apps with FastAPI Transcripts
Chapter: Users and HTML forms
Lecture: A basic user class
0:00 Let's start off this whole chapter by creating a basic user class. And then we can use that for our form,
0:07 our validation, our logging in. All that kind of stuff. So you can notice again that I have created a copy of what we finished for
0:13 chapter five. Now that's where we're starting for chapter six. Over here in our data section, we have package, we have release.
0:20 Let's add one more class, for the user. And let's call it class User, and it's gonna have a couple of things. It's gonna have a name. So, it has name,
0:30 it'll be a string. It's gonna have an email. It's tempting to say it has a password. You never, ever wanna store the password.
0:37 You wanna store a hash of the password and we're gonna use a really cool library
0:42 for this. Another thing that's nice to know when people sign up is: when did they create their account? So let's go over here and say a created_date,
0:49 and I'll just put that as None for the moment. There's two more things, we're gonna have a profile_image_url,
0:55 which is gonna just be some kind of string that we pass over, and we'll have last_login,
1:01 which is a datetime, perfect. So this is our basic user class that we're gonna work with. And this is optional, but we'll come and make it work
1:10 when we really do our actual thing with it. Let's give it a few pieces of information.
1:14 Let's say we're gonna pass over the name, the email and the hashed_password. Those will do it for us for now.
1:26 Perfect. So we're gonna go and create this, add couple of users with our form. Let them login through our user service,
1:33 things like that. Here's our basic User class. Remember, what we're going to do is convert this to a SQLAlchemy ORM model with basically these columns.
1:42 But until we get to the database in the next chapter, we're just gonna work with it in memory.