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 usersEndpoints
1. /
/Method: GET Serves the landing page.
2. /signin
/signinMethod: 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
/signupMethod: 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
/appMethod: GET Serves the dashboard page for logged-in users. Requires authentication. Displays the logged-in username.
5. /logout
/logoutMethod: GET Logs out the user by destroying their session.
Code Overview
index.js (Node.js server)
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)
index.html (Landing Page)A basic welcome page with navigation links to the login and signup pages.
signin.html (Login Page)
signin.html (Login Page)Form for user login. Sends a POST request to the /signin endpoint.
signup.html (Signup Page)
signup.html (Signup Page)Form for user registration. Sends a POST request to the /signup endpoint.
app.html (User Dashboard)
app.html (User Dashboard)Displays a personalized greeting with the logged-in username. Includes a logout link to end the session.
How to Run
Install dependencies:
Run the server:
Access the application: Open your browser and navigate to
http://localhost:3000.
File Contents
index.js
index.jsindex.html
index.htmlsignin.html
signin.htmlsignup.html
signup.htmlapp.html
app.htmlDownload
This code is sample code and may lack API key management and back-end processing. Therefore, please use at your own risk.
最終更新
役に立ちましたか?