#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Test it! Login to the app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One last thing I just want to run through
0:02 quickly is the fact that our user class does have a few
0:07 pre-defined methods and properties that we can implement
0:11 a lot easier without having to specify them manually
0:15 if you we use, user mixin from Flask.
0:19 So let's quickly pop into our models file here
0:23 and let's add user_mixin into our class here.
0:27 And this will allow us to actually authenticate
0:30 the user, check to see if the user's active
0:33 that stuff without having to manually code it in.
0:37 And this works sort of hand in hand with that login
0:40 required decorator that we saw previously.
0:43 So, in our user class definition here
0:47 let's have user mixin and we need to import that
0:52 from Flask logins.
0:54 From Flask login, import user_mixin.
0:59 Simple as that, let's get out of there
1:02 and let's also add that in to our routes.pi file
1:06 pop on the end here.
1:08 Append user_mixin onto that and that will allow us
1:13 to actually authenticate a lot easier.
1:17 Last but not least, before we really get started.
1:19 Let's pop down here to our login page.
1:23 What I wanted to call out that I failed to note
1:26 in the previous video was this here.
1:28 Login manager login view.
1:30 This here, login page, what we call here
1:34 needs to be the same name as our function
1:40 that people log in with.
1:42 All right, these need to be the same here.
1:45 So login page and login page will match
1:48 and then we're actually able to log in.
1:49 So with that said, let's actually log in.
1:53 Close out of that. Flask run.
1:57 Did everything work?
1:58 Yes it does work so let's bring up our browser.
2:01 Load the home page.
2:02 There you go, this is the home page.
2:04 You do not need to be logged in to access this page.
2:08 So let's head over to login page.
2:13 There we go, this is the page where user's
2:14 will log into the site.
2:16 Now let's throw in a bogus name.
2:17 Let's throw in, you know, test, log in, Zelda.
2:24 Only because I'm looking at a Zelda picture on my left.
2:27 Submit.
2:28 Invalid user name or password.
2:30 So, one other thing to point out here
2:34 let's go to our dashboard before we log in
2:38 and notice because we're not logged in
2:40 it actually redirects us to the log in page.
2:44 Now this is because of that log in page view
2:49 that we set up with the log in manager.
2:52 So the log in manager controls all of this.
2:54 It takes care of all of this for us.
2:56 It noted that we were trying to access a page
2:58 that was behind a login.
3:00 So it took us to the page we've defined as the log in page.
3:04 Now let's actually enter in a username
3:07 that exists in our database.
3:09 Julian ABC123 Submit.
3:12 And now we're logged in.
3:15 So I can go back to the index page.
3:19 Yep, you do not need to be logged in
3:21 and I can go back to the Pi bites dashboard
3:25 and we're still logged in.
3:26 And there you have it.
3:27 There is our Flask login.
3:30 We can create another page, you don't have to
3:32 but we will create another page in the next video.
3:35 Really quickly, just to log us out
3:37 and then we'll demonstrate how this all works.