Skip to content

Commit

Permalink
Merge pull request #328 from softrams/322
Browse files Browse the repository at this point in the history
feat(create initial seed user): update initial startup to create defa…
  • Loading branch information
skewled committed Oct 6, 2020
2 parents f5e2923 + 61ddc2a commit 79602e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,14 @@ $ npm run migration:run

_This command should be run with every new database migration_

## Insert First User
## Default credentials

1. Insert the first user by running the following command with the required arguments. Example:
An account is created on initial startup with the following credentials:

```
$ node dist/init/seed-user.js --firstName=John --lastName=OneOneSeven --email=spartan117@unsc.com --title='Master Chief Petty Officer' --password=blueTeam
```
- email: `admin@bulwark.com`
- password: `changeMe`

2. Start the server and login to Bulwark with the newly created user
Upon first login, update the default user password under the profile section.

## Built With

Expand Down
15 changes: 14 additions & 1 deletion src/routes/config.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import * as configController from './config.controller';
import { Config } from '../entity/Config';
import MockExpressResponse = require('mock-express-response');
import MockExpressRequest = require('mock-express-request');
import { User } from '../entity/User';
import { compare } from '../utilities/password.utility';

describe('config controller', () => {
beforeEach(() => {
return createConnection({
type: 'sqlite',
database: ':memory:',
dropSchema: true,
entities: [Config],
entities: [Config, User],
synchronize: true,
logging: false
});
Expand All @@ -21,6 +23,17 @@ describe('config controller', () => {
});
test('initalize config', async () => {
await configController.initialInsert();
const userAry = await getConnection().getRepository(User).find({});
const configAry = await getConnection().getRepository(Config).find({});
expect(userAry.length).toBe(1);
expect(configAry.length).toBe(1);
expect(userAry[0].firstName).toBe('Master');
expect(userAry[0].lastName).toBe('Chief');
expect(userAry[0].email).toBe('admin@bulwark.com');
expect(userAry[0].title).toBe('Spartan 117');
expect(userAry[0].active).toBeTruthy();
const initUsrPw = userAry[0].password;
expect(compare('changeMe', initUsrPw)).toBeTruthy();
});
test('save configuration success', async () => {
const config = new Config();
Expand Down
14 changes: 13 additions & 1 deletion src/routes/config.controller.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { getConnection } from 'typeorm';
import { Response, Request } from 'express';
import { Config } from '../entity/Config';
import { User } from '../entity/User';
import { encrypt } from '../utilities/crypto.utility';
import { validate } from 'class-validator';
import { generateHash } from '../utilities/password.utility';

export const initialInsert = async () => {
const configAry = await getConnection().getRepository(Config).find({});
const usrAry = await getConnection().getRepository(User).find({});
if (!configAry.length) {
const initialConfig = new Config();
initialConfig.companyName = null;
initialConfig.fromEmail = null;
initialConfig.fromEmailPassword = null;
await getConnection().getRepository(Config).save(initialConfig);
return;
}
if (!usrAry.length) {
const initialUser = new User();
initialUser.active = true;
initialUser.email = 'admin@bulwark.com';
initialUser.firstName = 'Master';
initialUser.lastName = 'Chief';
initialUser.title = 'Spartan 117';
initialUser.password = await generateHash('changeMe');
await getConnection().getRepository(User).save(initialUser);
}
};

Expand Down

0 comments on commit 79602e0

Please sign in to comment.