Add default admin user

This commit is contained in:
Christopher Cookman 2024-05-05 23:55:04 -06:00
parent dc517d9af3
commit 3ee589fdec
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
2 changed files with 28 additions and 14 deletions

View file

@ -32,7 +32,7 @@ A super basic, full of issues ticketing system for me to keep track of things I
4. Run `node .` to start the server. You can also use a process manager like pm2 to keep the server running. 4. Run `node .` to start the server. You can also use a process manager like pm2 to keep the server running.
- You can now reach the server at `http://localhost:3000` (or whatever port you specified in the `config.json` file). - You can now reach the server at `http://localhost:3000` (or whatever port you specified in the `config.json` file).
- Default administrator login is `admin` with password `admin`. You should change this immediately. - Default administrator login is `admin`, the password will be generated and printed to the console.
## TODO ## TODO

View file

@ -44,6 +44,15 @@ app.use((req, res, next) => {
}); });
// Helper functions // Helper functions
// basic password generator
const genPass = () => {
return Array.from({ length: 24 }, () => {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?";
return charset[Math.floor(Math.random() * charset.length)];
}).join("");
}
// Create user // Create user
const createUser = (username, password, authLevel) => { const createUser = (username, password, authLevel) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -457,7 +466,7 @@ app.post("/user/delete", isAuthenticated, (req, res) => {
}); });
app.post("/user/update", isAuthenticated, (req, res) => { app.post("/user/update", isAuthenticated, (req, res) => {
// TODO: Allow user to update their own password // TODO: Allow user to update their own password
}); });
app.get("/admin/createUser", isAuthenticated, (req, res) => { app.get("/admin/createUser", isAuthenticated, (req, res) => {
@ -546,18 +555,23 @@ app.get("/admin/listUsers", isAuthenticated, (req, res) => {
}); });
}); });
//var usersToBeMade = ["cludlow", "jjones", "rsasongko", "aszeremeta", "epatterson"]
app.listen(port, () => { app.listen(port, () => {
console.log(`Server listening on port ${port}`); console.log(`Server listening on port ${port}`);
// usersToBeMade.forEach((name) => { // If users table is empty create an admin user
// // Generate a random password, 24 characters long, containing uppercase, lowercase, numeric, and symbols db.get("SELECT * FROM users", (err, row) => {
// let password = Array.from({ length: 24 }, () => { if (err) {
// const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?"; console.error(err);
// return charset[Math.floor(Math.random() * charset.length)]; return;
// }).join(""); }
// createUser(name, password, 0) if (!row) {
// console.log(`Ticket system login for ${name} is ${password}`); let pass = genPass();
// }) createUser("admin", pass, 1)
.then(() => {
console.log(`Admin user created. Username: admin, Password: ${pass}`);
})
.catch((err) => {
console.error(err);
});
}
});
}); });