title
Creating a Login Page in Flask Using Sessions

description
In this I will use sessions in Flask to create a simple login form. Need one-on-one help with your project? I can help through my coaching program. Learn more here: https://prettyprinted.com/coaching Get the code from the video here: https://prettyprinted.com/l/YX2 Join my free course on the basics of Flask-SQLAlchemy: https://prettyprinted.com/flasksql Twitter: https://twitter.com/pretty_printed Github: https://github.com/prettyprinted

detail
{'title': 'Creating a Login Page in Flask Using Sessions', 'heatmap': [{'end': 198.629, 'start': 180.667, 'weight': 0.766}, {'end': 660.779, 'start': 628.385, 'weight': 0.749}, {'end': 1104.568, 'start': 1056.963, 'weight': 0.82}], 'summary': 'Covers flask app development, user concept and management in python, user authentication and session management, user id storage, and using the g object in flask for efficient data passing, along with promoting a free course on flash sql alchemy basics.', 'chapters': [{'end': 206.375, 'segs': [{'end': 24.893, 'src': 'embed', 'start': 0.389, 'weight': 0, 'content': [{'end': 6.59, 'text': "hey, everyone, in today's video i'm going to show you how to use sessions and flask through a very simple example of using a login form.", 'start': 0.389, 'duration': 6.201}, {'end': 7.09, 'text': 'so, basically,', 'start': 6.59, 'duration': 0.5}, {'end': 14.432, 'text': "what we're going to do is we're going to build a simple login form where you can put in a username and a password and if you can log in properly,", 'start': 7.09, 'duration': 7.342}, {'end': 20.453, 'text': 'then you will see your username whatever that is, in my case, anthony and then the user id number one.', 'start': 14.432, 'duration': 6.021}, {'end': 24.893, 'text': "so we won't be using a database for this, but we'll be using an in-memory data store.", 'start': 20.453, 'duration': 4.44}], 'summary': 'Demonstration of using sessions and flask with a simple login form, without database, but with in-memory data store.', 'duration': 24.504, 'max_score': 0.389, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U389.jpg'}, {'end': 60.581, 'src': 'embed', 'start': 32.377, 'weight': 2, 'content': [{'end': 37.742, 'text': 'You can go to prettyprinted.com or the link in the description below and you can check out the courses that I have.', 'start': 32.377, 'duration': 5.365}, {'end': 43.247, 'text': 'The best course for anyone watching in this video would probably be Flash SQL Alchemy Basics,', 'start': 38.142, 'duration': 5.105}, {'end': 51.154, 'text': 'which is a free course that covers various things that you can do in Flash SQL Alchemy creating different things,', 'start': 43.247, 'duration': 7.907}, {'end': 55.917, 'text': 'inserting data along with the different type of statements that you have in your query.', 'start': 51.154, 'duration': 4.763}, {'end': 60.581, 'text': 'So null and not null, order by, not equals and like, and so on.', 'start': 55.997, 'duration': 4.584}], 'summary': 'Visit prettyprinted.com for a free flash sql alchemy basics course covering data insertion, query statements, and more.', 'duration': 28.204, 'max_score': 32.377, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U32377.jpg'}, {'end': 127.144, 'src': 'embed', 'start': 96.205, 'weight': 1, 'content': [{'end': 100.567, 'text': 'So basically the user will fill out their username and the password, hit login.', 'start': 96.205, 'duration': 4.362}, {'end': 107.63, 'text': "And then, if it's successful, it will take them to this login page, where it's going to show their username eventually and their number,", 'start': 100.787, 'duration': 6.843}, {'end': 108.731, 'text': "as you've seen before.", 'start': 107.63, 'duration': 1.101}, {'end': 112.553, 'text': "So I'll just close these because we'll be seeing them inside the app from now on.", 'start': 109.231, 'duration': 3.322}, {'end': 118.776, 'text': 'And what I will start with is by creating an app.py file.', 'start': 114.754, 'duration': 4.022}, {'end': 127.144, 'text': 'And in here, I can start the import.', 'start': 125.203, 'duration': 1.941}], 'summary': 'Users will fill out username and password to login. successful login will display username and number.', 'duration': 30.939, 'max_score': 96.205, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U96205.jpg'}, {'end': 212.259, 'src': 'heatmap', 'start': 180.667, 'weight': 6, 'content': [{'end': 183.428, 'text': "So I'll change the Flask environment to development.", 'start': 180.667, 'duration': 2.761}, {'end': 188.951, 'text': 'So it will be in debug mode, and it will restart automatically whenever I make a change.', 'start': 183.509, 'duration': 5.442}, {'end': 190.892, 'text': "And I'll do Flask run.", 'start': 189.811, 'duration': 1.081}, {'end': 193.273, 'text': "So let's take a look.", 'start': 192.532, 'duration': 0.741}, {'end': 198.629, 'text': "So if I go to the index, nothing's there because I don't have anything on the index.", 'start': 194.286, 'duration': 4.343}, {'end': 201.851, 'text': 'But if I go to the login page, I see the login page.', 'start': 198.729, 'duration': 3.122}, {'end': 206.375, 'text': 'And if I go to profile, I see the profile page.', 'start': 202.052, 'duration': 4.323}, {'end': 212.259, 'text': "So of course nothing gets filled in yet because I don't have any kind of user, but that's what we're going to build.", 'start': 206.415, 'duration': 5.844}], 'summary': 'Switched flask environment to development for debug mode, auto-restart. login and profile pages functional.', 'duration': 31.592, 'max_score': 180.667, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U180667.jpg'}], 'start': 0.389, 'title': 'Flask app development', 'summary': 'Covers the development of a flask app, including the installation of flask, creation of login and profile templates, and setting up routes for the app with the ability to render the login and profile pages. it also demonstrates how to use sessions and flask by creating a simple login form without using a database and promotes a free course on flash sql alchemy basics.', 'chapters': [{'end': 71.937, 'start': 0.389, 'title': 'Using sessions and flask for login form', 'summary': 'Demonstrates how to use sessions and flask by creating a simple login form without using a database but an in-memory data store, and also promotes a free course on flash sql alchemy basics.', 'duration': 71.548, 'highlights': ['The tutorial focuses on building a simple login form using sessions and Flask, without utilizing a database, and instead employing an in-memory data store for simplicity.', 'The chapter promotes a free course on Flash SQL Alchemy Basics, covering various functionalities such as creating different things, inserting data, and different types of statements within queries.', "The video content includes a demonstration of using a login form to input a username and password, and upon successful login, the user's username is displayed along with their user id number.", 'The presenter mentions having courses available on prettyprinted.com, particularly recommending the Flash SQL Alchemy Basics course for viewers of the video.']}, {'end': 206.375, 'start': 72.358, 'title': 'Flask app development', 'summary': 'Discusses the development of a flask app, including the installation of flask, creation of login and profile templates, and setting up routes for the app with the ability to render the login and profile pages.', 'duration': 134.017, 'highlights': ['The user will fill out their username and password on the login page, and upon successful login, it will take them to the profile page, displaying their username and number.', 'The process involves creating an app.py file, importing necessary components like Flask class and render template, and setting up routes for login and profile pages.', "The development mode is activated with the Flask environment set to debug mode, allowing automatic restart whenever there's a change in the app."]}], 'duration': 205.986, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U389.jpg', 'highlights': ['The tutorial focuses on building a simple login form using sessions and Flask, without utilizing a database, and instead employing an in-memory data store for simplicity.', 'The user will fill out their username and password on the login page, and upon successful login, it will take them to the profile page, displaying their username and number.', 'The chapter promotes a free course on Flash SQL Alchemy Basics, covering various functionalities such as creating different things, inserting data, and different types of statements within queries.', "The video content includes a demonstration of using a login form to input a username and password, and upon successful login, the user's username is displayed along with their user id number.", 'The process involves creating an app.py file, importing necessary components like Flask class and render template, and setting up routes for login and profile pages.', 'The presenter mentions having courses available on prettyprinted.com, particularly recommending the Flash SQL Alchemy Basics course for viewers of the video.', "The development mode is activated with the Flask environment set to debug mode, allowing automatic restart whenever there's a change in the app."]}, {'end': 468.666, 'segs': [{'end': 255.552, 'src': 'embed', 'start': 226.555, 'weight': 1, 'content': [{'end': 231.479, 'text': "So instead of having a database, we're just going to have a global variable inside of our app.", 'start': 226.555, 'duration': 4.924}, {'end': 233.921, 'text': "So to do this, I'll do it up here, actually.", 'start': 231.619, 'duration': 2.302}, {'end': 235.102, 'text': "I'll create the user class.", 'start': 233.981, 'duration': 1.121}, {'end': 236.663, 'text': 'And this is going to be really, really simple.', 'start': 235.222, 'duration': 1.441}, {'end': 238.224, 'text': "So it's going to have a dunder init.", 'start': 237.003, 'duration': 1.221}, {'end': 242.406, 'text': "and it's going to take in a couple of things for the user, actually three things.", 'start': 239.185, 'duration': 3.221}, {'end': 251.49, 'text': "so we want to id, we want a username and we want a password, and then i'm going to just set these to the values that are passed in.", 'start': 242.406, 'duration': 9.084}, {'end': 255.552, 'text': 'so self id equals id and the same for username and password.', 'start': 251.49, 'duration': 4.062}], 'summary': 'Using a global variable for user data, creating a simple user class with id, username, and password.', 'duration': 28.997, 'max_score': 226.555, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U226555.jpg'}, {'end': 322.272, 'src': 'embed', 'start': 291.563, 'weight': 2, 'content': [{'end': 293.824, 'text': 'So users.append.', 'start': 291.563, 'duration': 2.261}, {'end': 296.586, 'text': 'And then I will create users.', 'start': 294.464, 'duration': 2.122}, {'end': 300.288, 'text': 'So ID is going to be 1 for this user.', 'start': 296.886, 'duration': 3.402}, {'end': 304.41, 'text': "Username is going to be equal to, let's say, Anthony.", 'start': 300.568, 'duration': 3.842}, {'end': 306.712, 'text': 'And then the password.', 'start': 305.411, 'duration': 1.301}, {'end': 310.924, 'text': "is going to be equal to, let's just say password.", 'start': 308.362, 'duration': 2.562}, {'end': 314.807, 'text': "So obviously not a good password and it's in plain text, but this is an example.", 'start': 310.964, 'duration': 3.843}, {'end': 317.149, 'text': "So I'll just type in password.", 'start': 315.267, 'duration': 1.882}, {'end': 322.272, 'text': 'And then what I want to do is I want to print all the users that I have, okay?', 'start': 317.569, 'duration': 4.703}], 'summary': "Creating user with id 1, username anthony, and password 'password'.", 'duration': 30.709, 'max_score': 291.563, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U291563.jpg'}, {'end': 426.366, 'src': 'embed', 'start': 394.691, 'weight': 0, 'content': [{'end': 397.755, 'text': 'Okay, so we know that our list of users is working correctly.', 'start': 394.691, 'duration': 3.064}, {'end': 399.097, 'text': "So that's really all we need to do.", 'start': 397.815, 'duration': 1.282}, {'end': 404.083, 'text': 'So let me remove the print statement and let me bring back the flask stuff.', 'start': 399.197, 'duration': 4.886}, {'end': 418.903, 'text': 'And basically the approach that I want to take is when the user fills out the login form, So I need to start the server so we can see it again.', 'start': 408.008, 'duration': 10.895}, {'end': 426.366, 'text': 'But when the user fills out the login form, my app is going to check if the username and password are correct.', 'start': 419.804, 'duration': 6.562}], 'summary': 'Confirming correct user list function, removing print statement, implementing login form validation.', 'duration': 31.675, 'max_score': 394.691, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U394691.jpg'}], 'start': 206.415, 'title': 'User concept and management in python', 'summary': 'Discusses building a user concept by creating a user class and appending user objects to a global variable list. it also explains creating a user management system in python using flask, involving user creation, addition, and login through a web form.', 'chapters': [{'end': 242.406, 'start': 206.415, 'title': 'Building user concept', 'summary': 'Discusses the process of building a user concept in a simple manner, including creating a user class and appending user objects to a global variable list instead of using a database.', 'duration': 35.991, 'highlights': ['Creating a user class and appending user objects to a global variable list instead of using a database', 'Defining a simple user class with a dunder init method that takes in three user attributes']}, {'end': 468.666, 'start': 242.406, 'title': 'User management system in python', 'summary': 'Explains the process of creating a user management system in python using flask, involving the creation and addition of users, and handling user login through a web form.', 'duration': 226.26, 'highlights': ['The chapter explains the process of creating a user management system in Python using Flask, involving the creation and addition of users, and handling user login through a web form. The chapter focuses on creating a user management system in Python using Flask, demonstrating the creation and addition of users, and handling user login through a web form.', 'The code involves storing user details such as ID, username, and password in a list, and displaying the users on the command line. The code involves storing user details such as ID, username, and password in a list, and displaying the users on the command line for validation.', 'The approach involves using Flask to handle user login through a web form, checking if the username and password are correct, and using a session to log the user in and redirect them to their profile. The approach involves using Flask to handle user login through a web form, checking if the username and password are correct, using a session to log the user in, and redirecting them to their profile.']}], 'duration': 262.251, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U206415.jpg', 'highlights': ['Creating a user management system in Python using Flask', 'Defining a simple user class with a dunder init method', 'Storing user details such as ID, username, and password in a list', 'Using Flask to handle user login through a web form']}, {'end': 671.704, 'segs': [{'end': 562.09, 'src': 'embed', 'start': 490.858, 'weight': 0, 'content': [{'end': 494.04, 'text': 'So I can get those by using your request.form and then username.', 'start': 490.858, 'duration': 3.182}, {'end': 496.782, 'text': 'And then I can do the same thing for password.', 'start': 494.06, 'duration': 2.722}, {'end': 510.587, 'text': "And then once I have those two, that's where I can do the check to see if the user is in fact a valid user and if they have the correct password.", 'start': 502.022, 'duration': 8.565}, {'end': 517.72, 'text': 'So what I want to do is I want to basically search the list that I have here for the username first.', 'start': 511.676, 'duration': 6.044}, {'end': 523.943, 'text': "So I can say something like this, user equals, and then it's going to be a list comprehension to keep this simple.", 'start': 518.561, 'duration': 5.382}, {'end': 530.028, 'text': "So I'm going to loop over this list users, and then I'm going to pull out anything that matches the username.", 'start': 523.984, 'duration': 6.044}, {'end': 542.616, 'text': 'So what I mean by that is I can say x for x in users And then I can say if x.username equals the username, right?', 'start': 530.228, 'duration': 12.388}, {'end': 549.681, 'text': 'So what this will do is it will check to see if the username that the user passed in is equal to any of the usernames in the list.', 'start': 542.976, 'duration': 6.705}, {'end': 552.442, 'text': "And we're going to assume that they're all going to be unique.", 'start': 549.781, 'duration': 2.661}, {'end': 554.584, 'text': "If they weren't unique, then this wouldn't work very well.", 'start': 552.643, 'duration': 1.941}, {'end': 562.09, 'text': 'but of course, in any real user system all the usernames will be unique, along with the passwords being unique as well.', 'start': 554.964, 'duration': 7.126}], 'summary': "Extracting and validating user credentials from a list using python's list comprehension for a real user system.", 'duration': 71.232, 'max_score': 490.858, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U490858.jpg'}, {'end': 671.704, 'src': 'heatmap', 'start': 628.385, 'weight': 1, 'content': [{'end': 629.627, 'text': 'So I need to bring in session.', 'start': 628.385, 'duration': 1.242}, {'end': 632.892, 'text': "So I'll go back to imports, session.", 'start': 629.647, 'duration': 3.245}, {'end': 643.789, 'text': "And then what I want to do is I want to say session and then I'll create a key and I'll call this user ID is going to be equal to user.id.", 'start': 635.563, 'duration': 8.226}, {'end': 651.795, 'text': "And what I also want to do is anytime a user attempts to log in, I'm going to pop out the user ID in the session to kind of start over.", 'start': 644.449, 'duration': 7.346}, {'end': 654.516, 'text': 'so this is what other sites actually do.', 'start': 652.535, 'duration': 1.981}, {'end': 660.779, 'text': "so if you attempt to log in when you're already logged in, it's going to remove your session and then try to create a new session.", 'start': 654.516, 'duration': 6.263}, {'end': 664.221, 'text': 'so if you happen to enter the wrong password when you try to log in again,', 'start': 660.779, 'duration': 3.442}, {'end': 669.443, 'text': "then you're going to be logged out and so you can enter the correct password, even though you were logged in before.", 'start': 664.221, 'duration': 5.222}, {'end': 671.704, 'text': 'so session pop.', 'start': 669.443, 'duration': 2.261}], 'summary': 'Implementing session management with user id key for secure logins.', 'duration': 36.141, 'max_score': 628.385, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U628385.jpg'}], 'start': 469.486, 'title': 'User authentication and session management', 'summary': 'Covers the process of gathering and validating user credentials, emphasizing the unique nature of usernames and passwords, and explains user login, session management, handling invalid passwords, and implementing security measures.', 'chapters': [{'end': 583.19, 'start': 469.486, 'title': 'User authentication process', 'summary': 'Explains the process of gathering the username and password from a form, checking their validity, and searching the list for the username, emphasizing the unique nature of usernames and passwords in real user systems.', 'duration': 113.704, 'highlights': ['Creating variables for username and password in the login form with method post.', 'Accessing the username and password using request.form and performing a check for validity.', 'Searching the list of users for the username using list comprehension and emphasizing the uniqueness of usernames and passwords in real user systems.']}, {'end': 671.704, 'start': 583.47, 'title': 'User login and session management', 'summary': "Explains the process of user login and session management, including user authentication and session management, with a focus on handling invalid passwords and implementing security measures to ensure user's login status.", 'duration': 88.234, 'highlights': ['The process of user login and session management is explained, focusing on handling invalid passwords. User login, session management, handling invalid passwords', "The session is set to have the user logged in by creating a key 'user ID' equal to user.id. Setting user session, creating 'user ID' key", 'Implementing security measures to remove the user session and create a new session if a user attempts to log in when already logged in. Security measures, removing user session, creating new session']}], 'duration': 202.218, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U469486.jpg', 'highlights': ['Emphasizing the uniqueness of usernames and passwords in real user systems', 'Implementing security measures to remove the user session and create a new session if a user attempts to log in when already logged in', "The session is set to have the user logged in by creating a key 'user ID' equal to user.id", 'Accessing the username and password using request.form and performing a check for validity', 'Searching the list of users for the username using list comprehension']}, {'end': 914.671, 'segs': [{'end': 695.945, 'src': 'embed', 'start': 671.704, 'weight': 0, 'content': [{'end': 678.653, 'text': "what i want to do is i want to pop the username, or not the username, but the user id, and we don't need to worry about returning anything.", 'start': 671.704, 'duration': 6.949}, {'end': 679.553, 'text': "So we'll put none.", 'start': 678.773, 'duration': 0.78}, {'end': 681.214, 'text': 'So session pop user ID.', 'start': 679.894, 'duration': 1.32}, {'end': 685.858, 'text': 'So this is going to remove the user ID if there is one already inside the session.', 'start': 681.254, 'duration': 4.604}, {'end': 690.121, 'text': "So we're just going to set the user ID inside the session to user.id.", 'start': 686.438, 'duration': 3.683}, {'end': 695.945, 'text': 'So important thing to note here is that the session here is something that gets translated into a cookie.', 'start': 690.681, 'duration': 5.264}], 'summary': 'Code removes existing user id from session and sets new user id.', 'duration': 24.241, 'max_score': 671.704, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U671704.jpg'}, {'end': 739.234, 'src': 'embed', 'start': 711.271, 'weight': 3, 'content': [{'end': 719.393, 'text': "But to avoid doing that in the first place, we're just going to pass very simple data to the session, which is just an ID, which is just an integer.", 'start': 711.271, 'duration': 8.122}, {'end': 724.097, 'text': "because we can't pass in a complete user object,", 'start': 720.573, 'duration': 3.524}, {'end': 731.546, 'text': "because that only exists inside of our app here and it doesn't really make sense in the context of a cookie that's going to live on the user's browser.", 'start': 724.097, 'duration': 7.449}, {'end': 739.234, 'text': "so we're just going to pass in a number to the session and then later we're going to take out that number and then Get the user object itself.", 'start': 731.546, 'duration': 7.688}], 'summary': 'Passing simple data (id) to session instead of user object for cookie.', 'duration': 27.963, 'max_score': 711.271, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U711271.jpg'}, {'end': 782.702, 'src': 'embed', 'start': 757.386, 'weight': 1, 'content': [{'end': 762.83, 'text': "And we're going to redirect them to the profile because after they log in they should be able to go to the profile page.", 'start': 757.386, 'duration': 5.444}, {'end': 765.112, 'text': 'So profile just like that.', 'start': 762.99, 'duration': 2.122}, {'end': 768.025, 'text': 'So now we need to think of the other cases.', 'start': 766.263, 'duration': 1.762}, {'end': 774.613, 'text': "So, in the case where the user doesn't exist, which it should, where the password is incorrect,", 'start': 768.526, 'duration': 6.087}, {'end': 777.656, 'text': 'we just want to redirect them back to the login screen so they can try again.', 'start': 774.613, 'duration': 3.043}, {'end': 782.702, 'text': 'So normally you would have some kind of message here, but that would make the code a little more complicated,', 'start': 777.856, 'duration': 4.846}], 'summary': 'Redirect users to profile after login, handle incorrect credentials.', 'duration': 25.316, 'max_score': 757.386, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U757386.jpg'}, {'end': 914.671, 'src': 'embed', 'start': 864.914, 'weight': 2, 'content': [{'end': 870.399, 'text': "So in the last video, I talked about how secret keys are necessary to work with sessions and I haven't set one here.", 'start': 864.914, 'duration': 5.485}, {'end': 879.089, 'text': "So what I'll do is app, underscore or app dot secret underscore key is going to be some secret key that only I should know.", 'start': 870.839, 'duration': 8.25}, {'end': 884.577, 'text': "So I'll say some secret key that only I should know.", 'start': 879.55, 'duration': 5.027}, {'end': 892.737, 'text': "That's pretty secret, right? So now if I refresh, Let's try this again.", 'start': 885.077, 'duration': 7.66}, {'end': 896.04, 'text': "So I'll try Anthony and then I'll try a password that doesn't exist.", 'start': 892.758, 'duration': 3.282}, {'end': 901.903, 'text': "I'll hit login and it redirects me to the login screen because the password isn't right.", 'start': 896.54, 'duration': 5.363}, {'end': 906.926, 'text': "So when I put in the correct password, which I forgot already, it's just password actually.", 'start': 902.023, 'duration': 4.903}, {'end': 911.789, 'text': 'So password, it redirects me to the profile page.', 'start': 907.567, 'duration': 4.222}, {'end': 914.671, 'text': 'So this is how I know that I was logged in successfully.', 'start': 911.929, 'duration': 2.742}], 'summary': "Using a secret key 'app.secret_key' to authenticate sessions, leading to successful login.", 'duration': 49.757, 'max_score': 864.914, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U864914.jpg'}], 'start': 671.704, 'title': 'User authentication and session management', 'summary': 'Discusses session management, user id storage, user login logic, redirection handling, form authentication, and session handling in a python application, including encountered errors and successful testing functionality.', 'chapters': [{'end': 754.424, 'start': 671.704, 'title': 'Session management and user id storage', 'summary': 'Discusses storing user ids in a session, emphasizing the use of simple data types due to the session being translated into a cookie and explaining the process of converting a user object to a format suitable for storing in a cookie.', 'duration': 82.72, 'highlights': ['The session is translated into a cookie, allowing only simple data types to be passed, such as an integer for the user ID, to avoid passing complete user objects, which are not suitable for cookies.', 'Storing just the user ID as a simple integer in the session is recommended, as it aligns with the context of a cookie and allows for later retrieval of the user object.', "The process involves popping any existing user ID from the session and setting it to the user's ID, followed by redirecting and obtaining the user object using the stored user ID."]}, {'end': 819.145, 'start': 757.386, 'title': 'User login and redirect logic', 'summary': 'Discusses the logic for user login and redirection, including handling cases such as user existence, incorrect password, and successful login redirection to the profile page.', 'duration': 61.759, 'highlights': ['The logic for redirecting users after login, including handling cases such as user existence, incorrect password, and successful login redirection to the profile page.', 'Handling the scenario where the user fails to provide the correct password for the selected username by redirecting back to the login screen.', "Ensuring all cases have return statements, including returning the template when it's not a post."]}, {'end': 914.671, 'start': 819.145, 'title': 'Python form authentication and session handling', 'summary': 'Describes the process of implementing form authentication and session handling in a python application, encountering an indentation error, setting up a secret key for sessions, and successfully testing login and redirection functionality.', 'duration': 95.526, 'highlights': ['The process of implementing form authentication and session handling in a Python application is described, encountering an indentation error and successfully resolving it.', 'Setting up a secret key for sessions is explained, emphasizing the necessity of secret keys for working with sessions.', 'Testing the login functionality is outlined, demonstrating the successful redirection to the profile page upon entering the correct password and username combination.', 'Encountering an indentation error on line 34 during the form authentication implementation process is highlighted, indicating the troubleshooting steps taken to resolve it.', 'The importance of secret keys for working with sessions is emphasized, with the demonstration of setting a secret key to enable session functionality.']}], 'duration': 242.967, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U671704.jpg', 'highlights': ["The process involves popping any existing user ID from the session and setting it to the user's ID, followed by redirecting and obtaining the user object using the stored user ID.", 'The logic for redirecting users after login, including handling cases such as user existence, incorrect password, and successful login redirection to the profile page.', 'The importance of secret keys for working with sessions is emphasized, with the demonstration of setting a secret key to enable session functionality.', 'Storing just the user ID as a simple integer in the session is recommended, as it aligns with the context of a cookie and allows for later retrieval of the user object.', 'Testing the login functionality is outlined, demonstrating the successful redirection to the profile page upon entering the correct password and username combination.']}, {'end': 1388.224, 'segs': [{'end': 960.591, 'src': 'embed', 'start': 915.231, 'weight': 0, 'content': [{'end': 919.174, 'text': 'So now let me add in the information to this profile so I can see it.', 'start': 915.231, 'duration': 3.943}, {'end': 923.805, 'text': "So to use that, I'm going to use the G object.", 'start': 920.362, 'duration': 3.443}, {'end': 927.067, 'text': 'So the G object is somewhat similar to a global variable.', 'start': 923.845, 'duration': 3.222}, {'end': 929.309, 'text': "So it's something you import from Flask.", 'start': 927.388, 'duration': 1.921}, {'end': 931.971, 'text': 'So from Flask, import G.', 'start': 929.689, 'duration': 2.282}, {'end': 937.555, 'text': 'And the way this works is basically G is going to be available across the request context.', 'start': 931.971, 'duration': 5.584}, {'end': 941.479, 'text': 'So a request is just when a user requests something from the server.', 'start': 937.796, 'duration': 3.683}, {'end': 943.48, 'text': 'So like they go to one particular route.', 'start': 941.499, 'duration': 1.981}, {'end': 951.566, 'text': 'From the beginning to the end of that process, you have like, a session or not a session context, but a request context.', 'start': 944.161, 'duration': 7.405}, {'end': 960.591, 'text': 'And G makes it easy to store data between different functions without having to pass things around directly.', 'start': 952.286, 'duration': 8.305}], 'summary': 'Using the g object from flask to store data across the request context, making it easier to pass data between functions.', 'duration': 45.36, 'max_score': 915.231, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U915231.jpg'}, {'end': 1014.638, 'src': 'embed', 'start': 985.604, 'weight': 3, 'content': [{'end': 990.667, 'text': 'And if the session exists, I want to put the user information inside of that G object.', 'start': 985.604, 'duration': 5.063}, {'end': 996.794, 'text': "so it's going to be available inside of other things that I may use inside of the request context.", 'start': 990.667, 'duration': 6.127}, {'end': 1003.55, 'text': "So to do that, it's actually going to be app and then before request.", 'start': 998.146, 'duration': 5.404}, {'end': 1007.253, 'text': 'So as you can imagine, this will happen before anything else happens.', 'start': 1004.311, 'duration': 2.942}, {'end': 1010.015, 'text': "And I'll call this before request as well.", 'start': 1008.073, 'duration': 1.942}, {'end': 1014.638, 'text': 'And what I want to do is I want to check to see if the user ID exists in the session.', 'start': 1010.815, 'duration': 3.823}], 'summary': 'Put user information in session for request context.', 'duration': 29.034, 'max_score': 985.604, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U985604.jpg'}, {'end': 1104.568, 'src': 'heatmap', 'start': 1056.963, 'weight': 0.82, 'content': [{'end': 1061.905, 'text': 'So if this actually happens, we want to put the user on the global object.', 'start': 1056.963, 'duration': 4.942}, {'end': 1070.752, 'text': 'So we can say g.user is going to be equal to user.', 'start': 1062.005, 'duration': 8.747}, {'end': 1078.235, 'text': "so now anywhere that we can use g, which is pretty much anywhere, we'll have access to the user if they're logged in already.", 'start': 1070.752, 'duration': 7.483}, {'end': 1085.258, 'text': 'so the way this works is, if we go to the profile inside of the templates, is where you can use g.', 'start': 1078.235, 'duration': 7.023}, {'end': 1087.739, 'text': 'so what i can do is i can say g dot.', 'start': 1085.258, 'duration': 2.481}, {'end': 1094.762, 'text': 'user dot name will give me the name of whoever is logged in and i can also get their number.', 'start': 1087.739, 'duration': 7.023}, {'end': 1103.247, 'text': 'so g, because we put that user object here on g.user.', 'start': 1094.762, 'duration': 8.485}, {'end': 1104.568, 'text': "So that's why we can do that.", 'start': 1103.407, 'duration': 1.161}], 'summary': 'By assigning g.user to the user, we ensure global access to user data, enabling access to user info like name and number.', 'duration': 47.605, 'max_score': 1056.963, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U1056963.jpg'}, {'end': 1179.604, 'src': 'embed', 'start': 1138.733, 'weight': 4, 'content': [{'end': 1161.24, 'text': "if we add in another user to the list so let's say users append user ID and then username is going to be Carlos and his password will be something simple,", 'start': 1138.733, 'duration': 22.507}, {'end': 1175.323, 'text': "okay. so now, if I go back and I log in with Carlos, Carlos, and then something simple, then we see Carlos's profile and then number three,", 'start': 1161.24, 'duration': 14.083}, {'end': 1178.304, 'text': 'because that is his user ID.', 'start': 1175.323, 'duration': 2.981}, {'end': 1179.604, 'text': "so we're almost done.", 'start': 1178.304, 'duration': 1.3}], 'summary': "Adding a new user 'carlos' with user id and logging in successfully reveals his profile and user id.", 'duration': 40.871, 'max_score': 1138.733, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U1138733.jpg'}, {'end': 1259.377, 'src': 'embed', 'start': 1231.196, 'weight': 5, 'content': [{'end': 1235.22, 'text': "So what I want to do is I want to check inside a profile to make sure that they're logged in.", 'start': 1231.196, 'duration': 4.024}, {'end': 1239.143, 'text': 'So I can say something like if not g.user.', 'start': 1235.72, 'duration': 3.423}, {'end': 1245.849, 'text': 'So if g.user is none, what I want to do is I want to abort 403, which is forbidden.', 'start': 1239.564, 'duration': 6.285}, {'end': 1250.232, 'text': 'So abort 403.', 'start': 1246.49, 'duration': 3.742}, {'end': 1252.873, 'text': "we won't have any special screen.", 'start': 1250.232, 'duration': 2.641}, {'end': 1253.774, 'text': 'or you know what.', 'start': 1252.873, 'duration': 0.901}, {'end': 1259.377, 'text': "to make this even better, i'll just redirect them to the login page, because it kind of fits with everything else.", 'start': 1253.774, 'duration': 5.603}], 'summary': 'Check if user is logged in; if not, redirect to login page.', 'duration': 28.181, 'max_score': 1231.196, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U1231196.jpg'}, {'end': 1330.476, 'src': 'embed', 'start': 1298.159, 'weight': 6, 'content': [{'end': 1301.441, 'text': "Password, and it redirects me to Anthony's profile.", 'start': 1298.159, 'duration': 3.282}, {'end': 1304.002, 'text': 'You are user ID number one.', 'start': 1301.981, 'duration': 2.021}, {'end': 1311.006, 'text': "So I know the actual session part of this tutorial is pretty simple, but that's because sessions in Flask are simple.", 'start': 1304.763, 'duration': 6.243}, {'end': 1315.268, 'text': 'But really for sessions to have meaning, there has to be like some bigger context.', 'start': 1311.066, 'duration': 4.202}, {'end': 1320.731, 'text': 'So like in the last video, I talked about how to create like dark mode with sessions.', 'start': 1315.328, 'duration': 5.403}, {'end': 1324.473, 'text': 'And in this video, I have like a little login system built around the session.', 'start': 1320.851, 'duration': 3.622}, {'end': 1330.476, 'text': "So, with these two videos, I think you'll have a better idea of how sessions can be used within your Flask app.", 'start': 1324.893, 'duration': 5.583}], 'summary': 'Tutorial demonstrates session usage in flask with login system, providing better understanding of session applications.', 'duration': 32.317, 'max_score': 1298.159, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U1298159.jpg'}], 'start': 915.231, 'title': 'Using g object and session management in flask', 'summary': 'Explains using the g object in flask to improve data passing efficiency within request context and implementing session management for user authentication, profile access, and error handling, demonstrating effective session usage.', 'chapters': [{'end': 1010.015, 'start': 915.231, 'title': 'Using the g object in flask', 'summary': 'Explains the use of the g object in flask to store data specific to individual requests, improving the efficiency of passing data between different functions within the request context.', 'duration': 94.784, 'highlights': ['The G object is used to store data specific to individual requests in Flask, making it easy to pass data between different functions without direct passing. The G object is used to store data specific to individual requests in Flask, simplifying the process of passing data between different functions without direct passing.', 'The G object is available across the request context, providing a way to store and access data for a single user during a request. The G object is available across the request context, providing a way to store and access data for a single user during a request.', 'Using the G object improves efficiency by eliminating the need to pass data around directly, making it specific to one individual request. Using the G object improves efficiency by eliminating the need to pass data around directly, making it specific to one individual request.', "The 'before request' method in Flask is used to check the session and store user information inside the G object at the beginning of the request. The 'before request' method in Flask is used to check the session and store user information inside the G object at the beginning of the request."]}, {'end': 1388.224, 'start': 1010.815, 'title': 'Flask session management', 'summary': 'Covers implementing session management in flask, including user authentication, profile access, and error handling, all while demonstrating the use of sessions for user persistence and providing context for effective session usage.', 'duration': 377.409, 'highlights': ['The user authentication process involves checking if the user ID exists in the session, then finding and storing the user data for access throughout the application, allowing seamless access to user information (e.g., name and number) upon successful login.', 'Error handling is implemented to restrict access to the profile page if the user is not logged in, redirecting users to the login page if necessary, ensuring a secure and seamless user experience.', 'The tutorial emphasizes the simplicity of session management in Flask while highlighting its importance in providing meaningful context for user interactions and persistence across app visits.']}], 'duration': 472.993, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/2Zz97NVbH0U/pics/2Zz97NVbH0U915231.jpg', 'highlights': ['The G object in Flask simplifies passing data between functions within a request.', 'Using the G object improves efficiency by eliminating the need to pass data directly.', 'The G object is available across the request context, providing a way to store and access data for a single user during a request.', "The 'before request' method in Flask is used to check the session and store user information inside the G object at the beginning of the request.", 'The user authentication process involves checking if the user ID exists in the session and storing user data for access throughout the application.', 'Error handling is implemented to restrict access to the profile page if the user is not logged in, ensuring a secure user experience.', 'The tutorial emphasizes the simplicity of session management in Flask and its importance in providing meaningful context for user interactions.']}], 'highlights': ['The tutorial emphasizes the simplicity of session management in Flask and its importance in providing meaningful context for user interactions.', 'The G object in Flask simplifies passing data between functions within a request.', 'Using the G object improves efficiency by eliminating the need to pass data directly.', "The 'before request' method in Flask is used to check the session and store user information inside the G object at the beginning of the request.", 'The user authentication process involves checking if the user ID exists in the session and storing user data for access throughout the application.', "The process involves popping any existing user ID from the session and setting it to the user's ID, followed by redirecting and obtaining the user object using the stored user ID.", 'The logic for redirecting users after login, including handling cases such as user existence, incorrect password, and successful login redirection to the profile page.', 'The importance of secret keys for working with sessions is emphasized, with the demonstration of setting a secret key to enable session functionality.', 'Storing just the user ID as a simple integer in the session is recommended, as it aligns with the context of a cookie and allows for later retrieval of the user object.', 'Testing the login functionality is outlined, demonstrating the successful redirection to the profile page upon entering the correct password and username combination.']}