mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
fixed a bit
This commit is contained in:
1 parent
25fe268ed6
commit
c62413eafa
4 files changed
+60
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
import { queryOne } from "@/lib/db";
|
||||||
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
|
export async function validateCredentials(username, password) {
|
||||||
|
const user = await queryOne("SELECT * FROM users WHERE username = ?", [
|
||||||
|
username,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (user && bcrypt.compareSync(password, user.password)) {
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
role: user.role,
|
||||||
|
teamId: user.team_id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { run } from "./db.js";
|
||||||
|
|
||||||
|
async function initializeDatabase() {
|
||||||
|
try {
|
||||||
|
// Create users table
|
||||||
|
await run(`
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT UNIQUE NOT NULL,
|
||||||
|
password TEXT NOT NULL,
|
||||||
|
role TEXT DEFAULT 'user',
|
||||||
|
team_id INTEGER,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Create teams table
|
||||||
|
await run(`
|
||||||
|
CREATE TABLE IF NOT EXISTS teams (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
code TEXT UNIQUE NOT NULL,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log("Database initialized successfully");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Database initialization error:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeDatabase();
|
||||||
Reference in new issue
Block a user