Guest User

Untitled

a guest
Feb 4th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import {
  2. Entity,
  3. PrimaryGeneratedColumn,
  4. Column,
  5. Unique,
  6. CreateDateColumn,
  7. UpdateDateColumn
  8. } from "typeorm";
  9. import { Length, IsNotEmpty } from "class-validator";
  10. import * as bcrypt from "bcryptjs";
  11.  
  12. @Entity()
  13. @Unique(["username"])
  14. export class User {
  15. @PrimaryGeneratedColumn()
  16. id: number;
  17.  
  18. @Column()
  19. @Length(4, 20)
  20. username: string;
  21.  
  22. @Column()
  23. @Length(4, 100)
  24. password: string;
  25.  
  26. @Column()
  27. @IsNotEmpty()
  28. role: string;
  29.  
  30. @Column()
  31. @CreateDateColumn()
  32. createdAt: Date;
  33.  
  34. @Column()
  35. @UpdateDateColumn()
  36. updatedAt: Date;
  37.  
  38. hashPassword() {
  39. this.password = bcrypt.hashSync(this.password, 8);
  40. }
  41.  
  42. checkIfUnencryptedPasswordIsValid(unencryptedPassword: string) {
  43. return bcrypt.compareSync(unencryptedPassword, this.password);
  44. }
  45. }
Add Comment
Please, Sign In to add comment