Skip to content

TeoJJss/fastapi-login-sys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Login System

This is a basic login system that will create ticket upon successful user login. The backend server is built using FastAPI.

Getting Started

Prerequisite

Python v3.11.6 is used for development.

Installing

Run the following commands to create a virtual environment and install all necessary dependencies:

python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

Then, run the following command to launch the backend server

uvicorn app:app

You will notice that a ".db" file is created. That is a SQLite database used to store data!
To launch frontend, double click index.html to open it in browser.

User Guide

index.html is the initial landing page for login, and home.html is only accessible upon successful login.
Please open the HTML files directly in browser, after launching the backend server.
The table below shows the existing user credentials for login:

Username Password
John Doe john123
Oyen cuteOyen
All the credentials are case-sensitive

After entering username and password accordingly, click "Login" button to login. Upon successful login, user will be redirected to home.html.
In home.html, user can click "Logout" hyperlink to log out. After logging out, the user cannot access home.html anymore.

Developer Guide

Before launching the backend server, developers should take note the following tips:
  1. To change the ".db" filename, do it at config.py.
  2. If you launch the backend server in different port number (other than 8000), please modify the host and port number at src/functions.js.
  3. If you would like to add more authenticated users, please modify the SQL in the insert_users_sql variable at services/service.py.

All authenticated users are stored in the USERS table. Upon successful login, the backend system will create a ticket and add both username and ticket string to the TICKETS table. The ticket will be saved in session variable too.
When home.html is accessed, the system will retrieve the ticket string in the session variable and check its existence in TICKETS table.
When user logout, the system delete the ticket string from the TICKETS table. The session variable is removed from the frontend side. This will restrict the user to access the home.html or other authenticated webpages.
Frontend and backend are integrated through FastAPI.