Guest User

Untitled

a guest
Dec 27th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import bcrypt = require("bcrypt-nodejs");
  2. import { Schema } from "mongoose";
  3. import mongoose = require("mongoose");
  4.  
  5. mongoose.Promise = global.Promise;
  6.  
  7. /**
  8. * This is Schema for User
  9. * @constant {UserSchema}
  10. */
  11. export const UserSchema = new Schema({
  12. id: {
  13. type: String,
  14. },
  15. username: {
  16. type: String,
  17. trim: true,
  18. unique: true,
  19. select: true,
  20. },
  21. name: {
  22. type: String,
  23. select: true,
  24. required: true,
  25. },
  26. password: {
  27. type: String,
  28. select: false,
  29. },
  30. }, {
  31. timestamps: {},
  32. });
  33.  
  34. UserSchema.methods.generateHash = function(password): boolean {
  35. return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
  36. };
  37.  
  38. UserSchema.methods.validPassword = function(password): boolean {
  39. return bcrypt.compareSync(password, this.password);
  40. };
Add Comment
Please, Sign In to add comment