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.
0:04 And then we can use that for our form,
0:06 our validation, our logging in. All that kind of stuff.
0:09 So you can notice again that I have created a copy of what we finished for
0:12 chapter five. Now that's where we're starting for chapter six.
0:15 Over here in our data section,
0:16 we have package, we have release.
0:19 Let's add one more class, for the user.
0:21 And let's call it class User, and it's gonna have a couple of things.
0:25 It's gonna have a name. So, it has name,
0:29 it'll be a string. It's gonna have an email.
0:32 It's tempting to say it has a password.
0:34 You never, ever wanna store the password.
0:36 You wanna store a hash of the password and we're gonna use a really cool library
0:41 for this. Another thing that's nice to know when people sign up is: when did
0:45 they create their account? So let's go over here and say a created_date,
0:48 and I'll just put that as None
0:50 for the moment. There's two more things, we're gonna have a profile_image_url,
0:54 which is gonna just be some kind of string that we pass
0:57 over, and we'll have last_login,
1:00 which is a datetime, perfect. So this is our basic user class that we're gonna
1:06 work with. And this is optional,
1:08 but we'll come and make it work
1:09 when we really do our actual thing with it.
1:11 Let's give it a few pieces of information.
1:13 Let's say we're gonna pass over the name, the email and the hashed_password.
1:19 Those will do it for us for now.
1:25 Perfect. So we're gonna go and create this, add couple of users with our form.
1:29 Let them login through our user service,
1:32 things like that. Here's our basic User class.
1:34 Remember, what we're going to do is convert this to a SQLAlchemy ORM
1:38 model with basically these columns.
1:41 But until we get to the database in the next chapter,
1:43 we're just gonna work with it in memory.