JSONDB Login System (Node.js)

This is a simple login and signup system using Node.js and the JSONDB API. It allows users to sign up, sign in, and access a user-specific dashboard. User data is stored and retrieved using the JSONDB API.

Project Structure

/               # Root directory
|-- index.js    # Node.js server code
|-- index.html  # Landing page
|-- signin.html # Login page
|-- signup.html # Signup page
|-- public/     
    |-- app.html  # Dashboard for logged-in users

Endpoints

1. /

Method: GET Serves the landing page.

2. /signin

Method: GET Serves the login page.

Method: POST Processes login requests. Authenticates the user by comparing the provided credentials with the data stored in JSONDB.

3. /signup

Method: GET Serves the signup page.

Method: POST Processes signup requests. Checks if the username already exists, and if not, registers a new user in JSONDB.

4. /app

Method: GET Serves the dashboard page for logged-in users. Requires authentication. Displays the logged-in username.

5. /logout

Method: GET Logs out the user by destroying their session.


Code Overview

index.js (Node.js server)

The main server script manages the routes and handles interactions with the JSONDB API.

Key Features:

  • Session management using express-session.

  • Static file serving for HTML files.

  • User authentication and registration integrated with JSONDB.

index.html (Landing Page)

A basic welcome page with navigation links to the login and signup pages.

signin.html (Login Page)

Form for user login. Sends a POST request to the /signin endpoint.

signup.html (Signup Page)

Form for user registration. Sends a POST request to the /signup endpoint.

app.html (User Dashboard)

Displays a personalized greeting with the logged-in username. Includes a logout link to end the session.


How to Run

  1. Install dependencies:

  2. Run the server:

  3. Access the application: Open your browser and navigate to http://localhost:3000.


File Contents

index.js

index.html

signin.html

signup.html

app.html


Download

4KB
開く

This code is sample code and may lack API key management and back-end processing. Therefore, please use at your own risk.

最終更新

役に立ちましたか?