Skip to content

Commit 7bdfcda

Browse files
committed
Setup improvements
1 parent b1e6045 commit 7bdfcda

File tree

6 files changed

+1085
-2689
lines changed

6 files changed

+1085
-2689
lines changed

db/index.js

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
11
const mysql = require('mysql');
22
const fs = require('fs');
3+
const bcrypt = require('bcryptjs');
34

45
console.log('Running SQL seed...');
56

67
// Read MySQL config
78
const config = JSON.parse(
8-
fs.readFileSync('ormconfig.json', {
9-
encoding: 'utf-8'
10-
})
9+
fs.readFileSync('ormconfig.json', {
10+
encoding: 'utf-8'
11+
})
1112
);
1213

1314
// Read SQL seed
1415
const seedQuery = fs.readFileSync('db/seeds.sql', {
15-
encoding: 'utf-8'
16+
encoding: 'utf-8'
1617
});
1718

1819
// Connect to database
1920
const connection = mysql.createConnection({
20-
host: config.host,
21-
user: config.username,
22-
password: config.password,
23-
database: config.database,
24-
multipleStatements: true
21+
host: config.host,
22+
user: config.username,
23+
password: config.password,
24+
database: config.database,
25+
multipleStatements: true
2526
});
2627

2728
connection.connect();
2829

30+
// Generate random password for initial admin account
31+
const psw = Math.random().toString(36).substring(7);
32+
const hash = bcrypt.hashSync(psw, 10);
33+
34+
// Query arguments
35+
const queryArgs = [hash];
36+
2937
// Run seed query
30-
connection.query(seedQuery, (err, res) => {
31-
if (err) {
32-
throw err;
33-
}
38+
connection.query(seedQuery, queryArgs, (err) => {
39+
if (err) {
40+
throw err;
41+
}
42+
43+
console.log('SQL seed completed! Password for initial admin account: ' + psw);
3444
});
3545

3646
connection.end();

db/seeds.sql

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ INSERT INTO user_role (name)
1313
VALUES ('Admin'),
1414
('User');
1515

16+
/* Insert admin account */
17+
INSERT INTO user (email, firstname, lastname, password, userRoleId)
18+
VALUES ('[email protected]', 'Admin', 'Admin', ?, 1);
19+
1620
/* Insert task status */
1721
INSERT INTO task_status (title, sort)
1822
VALUES ('To Do', 1),

gulpfile.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ const gulp = require('gulp')
22
const merge = require('gulp-merge-json')
33

44
const bases = {
5-
src: 'src/',
6-
dist: 'dist/',
7-
components: 'api/components/',
8-
output: 'output/'
5+
src: 'src/',
6+
dist: 'dist/',
7+
components: 'api/components/',
8+
output: 'output/'
99
}
1010

1111
const paths = {
12-
policy: 'api/components/**/policy.json',
13-
html: 'api/components/**/templates/*.html'
12+
policy: 'api/components/**/policy.json',
13+
html: 'api/components/**/templates/*.html'
1414
}
1515

1616
// Task for copying html templates
17-
gulp.task('copy', function() {
18-
gulp.src(paths.html, { cwd: bases.src }).pipe(gulp.dest(bases.components, { cwd: bases.dist }))
17+
gulp.task('copy', () => {
18+
return gulp.src(paths.html, { cwd: bases.src }).pipe(gulp.dest(bases.components, { cwd: bases.dist }));
1919
})
2020

2121
// Task for merging policies
2222
gulp.task('merge', () => {
23-
gulp
24-
.src(paths.policy, { cwd: bases.src })
25-
.pipe(merge({ fileName: 'policies.combined.json', concatArrays: true }))
26-
.pipe(gulp.dest(bases.output, { cwd: bases.dist }))
23+
return gulp
24+
.src(paths.policy, { cwd: bases.src })
25+
.pipe(merge({ fileName: 'policies.combined.json', concatArrays: true }))
26+
.pipe(gulp.dest(bases.output, { cwd: bases.dist }))
2727
})

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"devDependencies": {
2828
"@types/acl": "^0.4.37",
2929
"@types/bcrypt-nodejs": "0.0.30",
30+
"@types/bcryptjs": "^2.4.2",
3031
"@types/compression": "^1.0.1",
3132
"@types/cors": "^2.8.4",
3233
"@types/dotenv": "^6.1.0",
@@ -40,7 +41,7 @@
4041
"@types/passport-jwt": "^3.0.1",
4142
"@types/uuid": "^3.4.5",
4243
"@types/validator": "^10.11.1",
43-
"gulp": "^3.9.1",
44+
"gulp": "^4.0.2",
4445
"gulp-merge-json": "^1.3.1",
4546
"nodemon": "^1.19.1",
4647
"prettier": "^1.18.2",
@@ -50,12 +51,12 @@
5051
"tslint-config-airbnb": "^5.11.1",
5152
"tslint-config-prettier": "^1.17.0",
5253
"typedoc": "^0.14.2",
53-
"typescript": "3.5.2"
54+
"typescript": "^3.7.2"
5455
},
5556
"dependencies": {
5657
"acl": "^0.4.11",
5758
"axios": "^0.18.1",
58-
"bcrypt-nodejs": "0.0.3",
59+
"bcryptjs": "^2.4.3",
5960
"body-parser": "^1.18.3",
6061
"compression": "^1.7.3",
6162
"cors": "^2.8.5",

src/services/helper/utility.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compare, genSalt, hash } from 'bcrypt-nodejs';
1+
import { compare, genSalt, hash } from 'bcryptjs';
22
import { v1 as uuidv1 } from 'uuid';
33

44
import * as crypto from 'crypto';
@@ -29,17 +29,14 @@ export class UtilityService {
2929
*/
3030
public static hashPassword(plainPassword: string): Promise<string> {
3131
return new Promise((resolve, reject) => {
32-
genSalt(10, (err, salt) => {
32+
genSalt((err, salt) => {
3333
if (err) {
3434
reject(err);
3535
}
3636

3737
hash(
3838
plainPassword,
3939
salt,
40-
() => {
41-
// just leave this empty
42-
},
4340
(error, hashedVal) => {
4441
if (error) {
4542
reject(error);

0 commit comments

Comments
 (0)