feat: implement user authentication and license management system
- Added schema for users, licenses, and license hostnames in the database. - Created storage utility for reading and writing JSON files. - Developed user service for user registration, authentication, and retrieval. - Implemented authentication middleware to protect routes. - Built LicenseCard component to display license details. - Created SiteNav component for navigation with user authentication status. - Established AuthContext for managing authentication state and actions. - Developed Home page to display available plugins. - Created LicenseManager page for managing licenses with forms for creation and verification. - Implemented PluginDetail page to show detailed information about a specific plugin. - Added utility functions for date formatting.
This commit is contained in:
57
server/lib/schema.js
Normal file
57
server/lib/schema.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import db from "./db.js";
|
||||
|
||||
async function createUsersTable() {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
email VARCHAR(120) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
}
|
||||
|
||||
async function createLicensesTable() {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS licenses (
|
||||
id CHAR(36) NOT NULL PRIMARY KEY,
|
||||
user_id INT UNSIGNED NOT NULL,
|
||||
license_key VARCHAR(64) NOT NULL UNIQUE,
|
||||
label VARCHAR(255),
|
||||
note TEXT,
|
||||
repo_provider VARCHAR(32) NOT NULL,
|
||||
repo_name VARCHAR(255) NOT NULL,
|
||||
repo_base_url VARCHAR(255),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
last_version_check_at DATETIME NULL,
|
||||
primary_hostname VARCHAR(255) NULL,
|
||||
primary_hostname_normalized VARCHAR(255) NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
}
|
||||
|
||||
async function createLicenseHostnamesTable() {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS license_hostnames (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
license_id CHAR(36) NOT NULL,
|
||||
hostname VARCHAR(255) NOT NULL,
|
||||
normalized VARCHAR(255) NOT NULL,
|
||||
first_seen_at DATETIME NOT NULL,
|
||||
last_seen_at DATETIME NOT NULL,
|
||||
hits INT UNSIGNED NOT NULL DEFAULT 1,
|
||||
UNIQUE KEY unique_license_host (license_id, normalized),
|
||||
FOREIGN KEY (license_id) REFERENCES licenses(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
}
|
||||
|
||||
export async function ensureSchema() {
|
||||
await createUsersTable();
|
||||
await createLicensesTable();
|
||||
await createLicenseHostnamesTable();
|
||||
}
|
||||
Reference in New Issue
Block a user