Add bcrypt password encoding to account seeds

This commit is contained in:
rui hildt 2020-05-09 14:50:47 +02:00
parent 4b5a5b2477
commit aa3d51702f
2 changed files with 20 additions and 9 deletions

View File

@ -1,14 +1,16 @@
const bcrypt = require('bcryptjs');
const { saltingRounds } = require('../../config/config');
exports.seed = function (knex) {
// Deletes ALL existing entries
return knex('account')
.del()
.then(function () {
// Inserts seed entries
return knex('account').insert([
const accountSeeds = [
{
username: 'liza',
email: 'liza@example.com',
password: 'really-strong-password',
password: 'liza-password',
timezone: 'Europe/Brussels',
earliest_time: '09:30',
latest_time: '22:00',
@ -16,7 +18,7 @@ exports.seed = function (knex) {
{
username: 'emile',
email: 'emile@example.com',
password: 'really-strong-password',
password: 'emile-password',
timezone: 'America/New_York',
earliest_time: '09:00',
latest_time: '20:00',
@ -24,7 +26,7 @@ exports.seed = function (knex) {
{
username: 'jack',
email: 'jack@example.com',
password: 'really-strong-password',
password: 'jack-password',
timezone: 'Asia/Kolkata',
earliest_time: '10:30',
latest_time: '17:00',
@ -32,7 +34,7 @@ exports.seed = function (knex) {
{
username: 'cynthia',
email: 'cynthia@example.com',
password: 'really-strong-password',
password: 'cynthia-password',
timezone: 'Europe/Brussels',
earliest_time: '06:30',
latest_time: '12:00',
@ -40,11 +42,20 @@ exports.seed = function (knex) {
{
username: 'celine',
email: 'celine@example.com',
password: 'really-strong-password',
password: 'celine-password',
timezone: 'Europe/Brussels',
earliest_time: '10:30',
latest_time: '20:00',
},
]);
];
// Hash password for each user
accountSeeds.forEach((account) => {
let hash = bcrypt.hashSync(account.password, saltingRounds);
account.password = hash;
});
// Inserts seed entries
return knex('account').insert(accountSeeds);
});
};

View File

@ -252,7 +252,7 @@ exports.seed = function (knex) {
timezone: 'Europe/Brussels',
},
// Meeting 3 - Day 1
// Meeting 3 - Day 3
{
account_id: 1,
meeting_id: 'a8344a68-7961-4bff-bb3b-b288f3abcf1c',