Skip to content

Commit

Permalink
have default admin user and upload dir
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopysecurity committed Nov 21, 2020
1 parent d525abc commit bf41c0c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ userSchema.pre('save', function (next) {
if (!user.isModified || !user.isNew) {
next();
} else {
bcrypt.hash(user.password, stage.saltingRounds, function (err, hash) {
bcrypt.hash(user.password, 10, function (err, hash) {
if (err) {
console.log('Error hashing password for user', user.username);
next(err);
Expand Down
6 changes: 6 additions & 0 deletions public/uploads/admin/creds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<dvwsconfig>
<FirstName>Sam</FirstName>
<Username>admin</Username>
<Password>letmein</Password>
</dvwsconfig>
36 changes: 35 additions & 1 deletion startup_script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
var mysql = require('mysql');
require('dotenv').config();

const mongoose = require('mongoose');

const User = require('./models/users');


const connHost = process.env.SQL_LOCAL_CONN_URL;
const connUser = process.env.SQL_username;
const connPass = process.env.SQL_password;

const connUri = process.env.MONGO_LOCAL_CONN_URL;

var connection = mysql.createConnection({
host: connHost,
Expand All @@ -27,3 +32,32 @@ connection.connect(function (err) {

});
});

function createAdmin() {
mongoose.connect(connUri, { useNewUrlParser : true, useUnifiedTopology: true }, (err) => {
let result = {};



const user = new User({
username: "admin",
password: "letmein",
admin: true
});

user.save((err, user) => {
if (!err) {
console.log(user);
} else {
result.error = err;
console.log(result.error);
}
// Close the connection after saving
mongoose.disconnect();
});
});

}


createAdmin()

0 comments on commit bf41c0c

Please sign in to comment.