In this tutorial we'll try to build a login and user authentication system in our todo application.
We'll do following tasks step-by-step for building the user login and authorization system.
-
Create a login page.
- Add a new url for the login page
- Create a login form template
- Create a view function to render the login page
- Add a link in the home page to go to login
-
Authenticate the user when login form submitted
- Add a new url for login form submission.
- Add a new view function to login and authenticate the user.
- It should redirect the user to home page if login was successful.
- It should redirect to the same for if login failed and show messages.
- Hide the login link if user has been logged in.
- Display the username instead of the Login in the header if user is logged in.
-
Create a signup page.
- Add a new url for the signup page
- Create a signup form template
- Create a view function to render the signup page
- Add a link in the home page to go to signup
-
Authorization
- Allow only the logged in users to view the todo list
- Allow only the logged in users to view the Add todo form
- Allow only the logged in users to edit the Todo item
- Allow only the logged in users to delete the Todo item
- Allow only the logged in users to view the home page. So, redirect the user to login if user is not logged in.