Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require("mongoose");
- const passwordHash = require("password-hash");
- const jwt = require("jwt-simple");
- const config = require("../config/config");
- const userSchema = mongoose.Schema(
- {
- email: {
- type: String,
- lowercase: true,
- trim: true,
- unique: true,
- required: true
- },
- password: {
- type: String,
- required: true
- }
- },
- { timestamps: { createdAt: "created_at" } }
- );
- userSchema.methods = {
- authenticate: function(password) {
- return passwordHash.verify(password, this.password);
- },
- getToken: function() {
- return jwt.encode(this, config.secret);
- }
- };
- module.exports = mongoose.model("User", userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement