mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 17:59:25 +00:00
Implemented User.creareUser
This commit is contained in:
42
lib/User.js
42
lib/User.js
@@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||
|
||||
class User {
|
||||
@@ -60,14 +63,47 @@ class User {
|
||||
|
||||
login() {
|
||||
|
||||
static async hashPassword(password) {
|
||||
return await bcrypt.hash(password, 10);
|
||||
}
|
||||
|
||||
static hashPassword(password) {
|
||||
static async createUser(type, fname, oname, lname, email, password) {
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
|
||||
}
|
||||
const uuid = crypto.randomUUID();
|
||||
const hashedPassword = await User.hashPassword(password);
|
||||
|
||||
static createUser() {
|
||||
const sql = `
|
||||
insert into ${type} (
|
||||
${type}Id,
|
||||
email,
|
||||
firstName,
|
||||
otherNames,
|
||||
lastName,
|
||||
password)
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
||||
`;
|
||||
|
||||
await conn.runQuery(sql, [
|
||||
uuid,
|
||||
email,
|
||||
fname,
|
||||
oname,
|
||||
lname,
|
||||
hashedPassword
|
||||
]);
|
||||
|
||||
let res;
|
||||
switch (type) {
|
||||
case 'account':
|
||||
res = new (require('./Account'))(uuid);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Cannot create user of type ${type}`);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static getUserByEmail() {
|
||||
|
||||
Reference in New Issue
Block a user