Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. const mongoose = require("mongoose");
  2. const passwordHash = require("password-hash");
  3. const jwt = require("jwt-simple");
  4. const config = require("../config/config");
  5.  
  6. const userSchema = mongoose.Schema(
  7. {
  8. email: {
  9. type: String,
  10. lowercase: true,
  11. trim: true,
  12. unique: true,
  13. required: true
  14. },
  15. password: {
  16. type: String,
  17. required: true
  18. }
  19. },
  20. { timestamps: { createdAt: "created_at" } }
  21. );
  22.  
  23. userSchema.methods = {
  24. authenticate: function(password) {
  25. return passwordHash.verify(password, this.password);
  26. },
  27. getToken: function() {
  28. return jwt.encode(this, config.secret);
  29. }
  30. };
  31.  
  32. module.exports = mongoose.model("User", userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement