Add default admin user
This commit is contained in:
parent
dc517d9af3
commit
3ee589fdec
|
@ -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.
|
||||
|
||||
- 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
|
||||
|
||||
|
|
38
index.js
38
index.js
|
@ -44,6 +44,15 @@ app.use((req, res, next) => {
|
|||
});
|
||||
|
||||
// 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
|
||||
const createUser = (username, password, authLevel) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -546,18 +555,23 @@ app.get("/admin/listUsers", isAuthenticated, (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
//var usersToBeMade = ["cludlow", "jjones", "rsasongko", "aszeremeta", "epatterson"]
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}`);
|
||||
// usersToBeMade.forEach((name) => {
|
||||
// // Generate a random password, 24 characters long, containing uppercase, lowercase, numeric, and symbols
|
||||
// let password = Array.from({ length: 24 }, () => {
|
||||
// const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?";
|
||||
// return charset[Math.floor(Math.random() * charset.length)];
|
||||
// }).join("");
|
||||
// createUser(name, password, 0)
|
||||
// console.log(`Ticket system login for ${name} is ${password}`);
|
||||
// })
|
||||
// If users table is empty create an admin user
|
||||
db.get("SELECT * FROM users", (err, row) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
if (!row) {
|
||||
let pass = genPass();
|
||||
createUser("admin", pass, 1)
|
||||
.then(() => {
|
||||
console.log(`Admin user created. Username: admin, Password: ${pass}`);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue