Skip to content
Permalink
Browse files

Drop default user creation at server startup

It causes too much unnecessary work, since default user creation is a
one-time event.
  • Loading branch information...
lovett committed Apr 27, 2019
1 parent f41f083 commit 773fd84c080e7f2f9548c07d739c9f92810dd15f
Showing with 3 additions and 13 deletions.
  1. +0 −2 config-test.json
  2. +1 −1 server/User.ts
  3. +2 −4 server/db.ts
  4. +0 −6 server/server.ts
@@ -3,7 +3,5 @@
"NOTIFIER_HTTP_PORT": 9080,
"NOTIFIER_WEBSOCKET_PORT": 9080,
"NOTIFIER_FORCE_HTTPS": 1,
"NOTIFIER_DEFAULT_USER": "test",
"NOTIFIER_DEFAULT_PASSWORD": "test",
"NOTIFIER_DB": "test.sqlite"
}
@@ -2,7 +2,7 @@ import * as crypto from 'crypto';
import * as util from 'util';

export default class User {
public static passwordToHash(password: string): string {
public static hashPassword(password: string): string {
const buf = crypto.randomBytes(this.hashKeylength);
const salt = buf.toString('hex');

@@ -52,14 +52,12 @@ export async function getUserIdByToken(key: string, value: string): Promise<numb
}
}


export async function addUser(username: string, password: string): Promise<User | null> {
const sql = `INSERT INTO "Users"
(username, "passwordHash", "createdAt", "updatedAt")
VALUES ($1, $2, NOW(), NOW())
ON CONFLICT ON CONSTRAINT "Users_username_key" DO NOTHING`;
VALUES ($1, $2, NOW(), NOW())`;

const passwordHash = User.passwordToHash(password);
const passwordHash = User.hashPassword(password);

try {
const res = await pool.query(sql, [username, passwordHash]);
@@ -56,8 +56,6 @@ nconf.defaults({
NOTIFIER_BADGE_BASE_URL: '/svg',
NOTIFIER_BASE_URL: '/',
NOTIFIER_DB_DSN: 'postgres://notifier:notifier@localhost:5432/notifier',
NOTIFIER_DEFAULT_PASSWORD: undefined,
NOTIFIER_DEFAULT_USER: undefined,
NOTIFIER_FORCE_HTTPS: 0,
NOTIFIER_HTTP_IP: '127.0.0.1',
NOTIFIER_HTTP_PORT: 8080,
@@ -162,10 +160,6 @@ if (!module.parent) {

(async () => {
app.locals.expirationCache = await db.getExpiringMessages();
db.addUser(
app.locals.config.get('NOTIFIER_DEFAULT_USER'),
app.locals.config.get('NOTIFIER_DEFAULT_PASSWORD'),
);
})();

const port = nconf.get('NOTIFIER_HTTP_PORT');

0 comments on commit 773fd84

Please sign in to comment.
You can’t perform that action at this time.