forked from UKSOURCE/ipv6
Adding login admin, fix ipv6 Vienamese version, add env example
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import mongoose from "mongoose";
|
||||
import User from "../models/User";
|
||||
import * as dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import crypto from "crypto";
|
||||
|
||||
dotenv.config({ path: path.join(__dirname, "../.env") });
|
||||
|
||||
function hashPassword(password: string) {
|
||||
return crypto.createHash("sha256").update(password).digest("hex");
|
||||
}
|
||||
|
||||
async function seedAdmin() {
|
||||
const MONGODB_URI = process.env.MONGODB_URI;
|
||||
|
||||
if (!MONGODB_URI) {
|
||||
console.error("MONGODB_URI not found");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await mongoose.connect(MONGODB_URI);
|
||||
console.log("Connected to MongoDB");
|
||||
|
||||
const adminEmail = "adminipv6@mail.com".toLowerCase().trim();
|
||||
const adminPassword = "adminipv6A@a";
|
||||
const hashedPassword = hashPassword(adminPassword);
|
||||
|
||||
// Xóa sạch user cũ để tránh xung đột
|
||||
await User.deleteMany({ email: adminEmail });
|
||||
|
||||
await User.create({
|
||||
email: adminEmail,
|
||||
password: hashedPassword,
|
||||
});
|
||||
|
||||
console.log("SUCCESS: Admin account created/refreshed with hashed password.");
|
||||
console.log(`Email: ${adminEmail}`);
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
} finally {
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
seedAdmin();
|
||||
Reference in New Issue
Block a user