🚧 better uuid + starting hashing implementation

ref #14
This commit is contained in:
2020-12-04 17:04:33 +01:00
parent b47fad2c3a
commit f1629440fe
3 changed files with 19 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
import { IsInt, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
import { User } from '../models/User';
import { getConnectionManager } from 'typeorm';
import * as argon2 from "argon2";
import { IsInt, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
import * as uuid from 'uuid';
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../errors/CreateUserErrors';
import { UserGroup } from './UserGroup';
import { User } from '../models/User';
export class CreateUser {
@IsString()
@@ -24,6 +24,8 @@ export class CreateUser {
@IsInt()
@IsOptional()
groupId?: number[] | number
@IsUUID("5")
uuid: string;
public async toUser(): Promise<User> {
let newUser: User = new User();
@@ -39,12 +41,16 @@ export class CreateUser {
throw new UserGroupNotFoundError();
}
const new_uuid = uuid.v4()
newUser.email = this.email
newUser.username = this.username
newUser.firstname = this.firstname
newUser.middlename = this.middlename
newUser.lastname = this.lastname
newUser.uuid = new_uuid
// TODO: hash password here or in controller/ in User model via setter?
this.password = await argon2.hash(this.password);
newUser.password = this.password
console.log(newUser)

View File

@@ -1,8 +1,8 @@
import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm";
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, isUUID, } from "class-validator";
import { UserGroup } from './UserGroup';
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator";
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Permission } from './Permission';
import { UserAction } from './UserAction';
import { UserGroup } from './UserGroup';
/**
* Defines a admin user.
@@ -20,9 +20,7 @@ export class User {
/**
* autogenerated uuid
*/
@IsOptional()
@IsInt()
@Generated("uuid")
@IsUUID("5")
uuid: string;
/**