Example #1
0
	poster: String,
	subscribers: [{
		type: mongoose.Schema.Types.ObjectId,
		ref: 'User'
	}],
	episodes: [{
		season: Number,
		episodeNumber: Number,
		episodeName: String,
		firstAired: Date,
		overview: String
	}]
});

var userSchema = new mongoose.Schema({
	email: { type: String, unique: true },
	password: String
});

userSchema.pre('save', function(next){
	// 中间件 需等待中间件执行完后在执行其余操作
	var user = this;
	if(!user.isModified('password')) return next();
	// 当密码没被修改时执行下一步操作next(),反之执行下一步操作
	bcrypt.genSalt(10, function(err, salt){
		if(err) return next(err);
		bcrypt.hash(user.password, salt, function(err, hash){
			if(err) return next(err);
			user.password = hash;
			next();
		});
	});
Example #2
0
var mongoose = require('mongoose');
var bcrypt = require('bcrypt');

var userSchema = new mongoose.Schema({
  firstName: String,
  lastName: String,
  email: { type: String, required: [true, 'Email is required'], unique: true },
  password: String,
  isAdmin: { type: Boolean, default: false  },
  created_at: Date,
  updated_at: Date,
  // softDeleted: { type: Boolean, default: false },
  fb: {
    id: String,
    access_token: String,
    firstName: String,
    lastName: String,
    email: String
  },
  habits: [{
    type: mongoose.Types.ObjectId,
    ref: 'Habit'
  }]
});

// on every save, add the date
userSchema.pre('save', function(next) {
  // get the current date
  var currentDate = new Date();
  // change the updated_at field to current date
  this.updated_at = currentDate;
Example #3
0
var mongoose = require('mongoose');
var bcrypt = require('bcrypt');
var SALT_WORK_FACTOR = 10;

var userSchema = new mongoose.Schema({
    firstName: {
        type: String,
        required: true
    },
    lastName: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true,
        unique: true
    },
    userName: {
        type: String,
        required: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    }
});

userSchema.pre('save', function(next) {
    var user = this;
Example #4
0
var UserSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    unique: true
  },
  // password will be hashed with salt appended using bcrypt
  password: {
    type: String,
    required: true
  },
  profilePhotoUrl: {
    type: String,
    default: 'http://jennstrends.com/wp-content/uploads/2013/10/bad-profile-pic-2.jpeg'
  },
  favorites: {
    type: Array,
    default: []
  },
  friends: {
    type: Array,
    default: []
  },
  friendRequests: {
    type: Array,
    default: []
  },
  groups: {
    type: Array,
    default: []
  },
  salt: String
});
Example #5
0
var schema = new mongoose.Schema({
    firstName: String,
    lastName: String,
    email: {
        type: String
    },
    password: {
        type: String
    },
    store: {
        type: mongoose.Schema.Types.ObjectId, ref: 'Store'
    },
    orders:[{
        type: mongoose.Schema.Types.ObjectId, ref: 'Order'
    }],
    salt: {
        type: String
    },
    twitter: {
        id: String,
        username: String,
        token: String,
        tokenSecret: String
    },
    facebook: {
        id: String
    },
    google: {
        id: String
    }
}, { collection: 'users', discriminatorKey : '_type' });
Example #6
0
var mongoose = require('mongoose')
var uuid = require('node-uuid')
var UserHasRole = require('./user-has-role')
//var q = require('q')

var UserSchema = new mongoose.Schema({
  email: {
    type: String,
    required: true,
    unique: true
  },
  name: {
    type: String
  },
  password: {
    type: String,
    required: true
  },
  token: {
    type: String,
    unique: true,
    default: uuid.v4
  }
})

UserSchema.static('rolesOfUser')

module.exports = mongoose.model('User', UserSchema)
Example #7
0
import mongoose, { Schema } from 'mongoose';

const CompanySchema = new mongoose.Schema({
  name: { type: String },
  name_lower: { type: String, unique: true, lowercase: true },
  address_id: {type: Schema.Types.ObjectId, ref: 'Address'},
  description: { type: String }, 
  foundedDate: { type: Date },
  size: { type: Number },
  websiteUrl: { type: String },
  logoUrl: { type: String },
  specialties: { type: Array, default: []},
  industry: { type: String },
  roleUpdatedAt: { type: Date }
}, {timestamps: true});

function lowerCaseName(next) {
  const company = this;
  if (company.name) company.name_lower = company.name.toLowerCase().replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"").split(' ').join('_');
  return next();
}

CompanySchema.pre('save', lowerCaseName);

export default mongoose.model('Company', CompanySchema);
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
	name: String,
	description: String,
	img_url: String,
	target_url: String,
	display_sort: Number,
	status: {
		type: String,
		enum: {
			values: '有效|无效'.split('|'),
			message: 'enum validator failed for path {PATH} with value {VALUE}',
		}
	},
});

schema.set('collection', 'platform.carousels');

module.exports = exports = function(connection){
	connection = connection || mongoose;
	return connection.model('PlatformCarousel', schema);
};
Example #9
0
var CommentSchema = new mongoose.Schema({
      movie: {
      	type: ObjectId,
      	ref: 'Movie'
      },
      from: {
      	type: ObjectId,
      	ref: 'User'
      },
      reply: [{
      	from: {
      		type: ObjectId,
      		ref: 'User'
      	},
	      to: {
	      	type: ObjectId,
	      	ref: 'User'
	      },
	      content: String
      }],
      content: String,
      meta: {
          createAt: {
              type: Date,
              default: Date.now()
          },
          updateAt: {
              type: Date,
              default: Date.now()
          }
      }
  });
Example #10
0
const bandSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    index: true,
    unique: true,
  },
  submitted_by: {
    type: String,
    required: true,
  },
  children: [{
    type: Schema.ObjectId,
    ref: 'Vote',
  },
  ],
  users_who_voted_for: {
    type: Array,
  },
  vote_count: {
    type: Number,
    default: 0,
    index: true,
  },
  created_at: {
    type: Date,
    default: Date.now,
  },
  updated_at: {
    type: Date,
    default: Date.now,
  },
}, { strict: true });
import mongoose from 'mongoose';
import AddressModel from './AddressModel';
import PaymentModel from './PaymentModel';
import {Days} from '../../utils/enums'


let CustomerSchema = new mongoose.Schema({
  name: String,
  billing_day: {
    type: Number,
  },
  billing_address: {type: mongoose.Schema.Types.ObjectId, ref: 'Address' },
  service_addresses: [{type: mongoose.Schema.Types.ObjectId, ref: 'Address' }],
  payments: [{type: mongoose.Schema.Types.ObjectId, ref: 'Payment' }],
  active: Boolean
});

CustomerSchema.set('toJSON', {getters: true});

export default mongoose.model('Customer', CustomerSchema);
Example #12
0
var mongoose = require("mongoose");
var cartsModel = require("./cartsModel");
var ordersModel = require("./ordersModel");
var bcrypt = require("bcrypt");
var q = require("q"); //because in node and the backend, we now need to require this (angular has it's own "q" built in library)

var usersModel = new mongoose.Schema({
  name: {type: String, required: true},
  email: {type: String, required: true, unique: true, index: true},
  password: {type: String, required: true},
  cart: [cartsModel],
  orders: [ordersModel]
});

//pre('save') is mongoose middleware that runs before every user is created
usersModel.pre('save', function(next) {
  var user = this;
  //take password and encrypt it
  bcrypt.genSalt(10, function(err, salt) {
    bcrypt.hash(user.password, salt, function(err, hash) {
      console.log('Password hash: ', hash); //don't do in production
      user.password = hash;
      next();
    });
  });
});

usersModel.methods.verifyPassword = function(password) {
  var deferred = q.defer();
  var user = this;
  bcrypt.compare(password, user.password, function(err, res) {
Example #13
0
var express = require('express');
var mongoose = require('mongoose');
var encryptor = require('mongoose-encryption');

//encKey generated using command - openssl rand -base64 32;
var encKey = process.env.encKey;
//sigKey generated using command - openssl rand -base64 64;
var sigKey = process.env.sigKey;

var SQMSchema = new mongoose.Schema({
    id: Number,
    content: String,
    choices: Object,
    correctChoice: String,
    category: String,
    image: String
});
//encrypt fields
SQMSchema.plugin(encryptor, { encryptionKey: encKey, signingKey: sigKey, encryptedFields: ['content', 'correctChoice', 'choices'] });

module.exports = mongoose.model('SQMModel', SQMSchema);
Example #14
0
/* globals require, module */ 

'use strict'; 

var mongoose = require('mongoose'),
	bcrypt = require('bcrypt'), 
	SALT_WORK_FACTOR = 10; 

var userSchema = new mongoose.Schema({
	username: { type: String, required: true, unique: true, index: true },
	password: { type: String, required: true },
	joined: { type: Date, default: Date.now },
	role: { type: String, default: 'Author'},
	meta: {
		fullname: String, 
		website: String, 
	}
});

// add methods, static, virtuals, etc. to userSchema here

// remove spaces, invalid characters from username
// userSchema.pre('save', function(next) {
// 	// code here
// 	next(); 
// }); 

// Hash password with bcrypt before save
userSchema.pre('save', function(next) {
	var user = this; 
	if (!user.isModified('password')) return next; 
Example #15
0
// Dependencies
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');

// hostel schema
var hostelSchema   = new mongoose.Schema({
    hostel_name: {
        type: String,
        required: true,
        unique: true,
        uniqueCaseInsensitive: true
    }
});


// Apply the uniqueValidator plugin to userSchema. 
hostelSchema.plugin(uniqueValidator);

var Hostel = mongoose.model('hostels',hostelSchema);

// CRUD - Create Read Update Delete

// To add hostel
module.exports.addHostel = function(body,res){
    var hostel =new Hostel;
    hostel.hostel_name = body.hostel_name;
    
    hostel.save(function(err){
        // save() will run insert() command of MongoDB.
        // it will add new data in collection.
        var response;
Example #16
0
var express = require('express');
var logger = require('morgan');
var jwt = require('jwt-simple');
var moment = require('moment');
var mongoose = require('mongoose');
var request = require('request');

var config = require('./config');

var userSchema = new mongoose.Schema({
  email: { type: String, unique: true, lowercase: true },
  password: { type: String, select: false },
  displayName: String,
  picture: String,
  facebook: String,
  foursquare: String,
  google: String,
  github: String,
  linkedin: String,
  live: String,
  yahoo: String,
  twitter: String
});

userSchema.pre('save', function(next) {
  var user = this;
  if (!user.isModified('password')) {
    return next();
  }
  bcrypt.genSalt(10, function(err, salt) {
    bcrypt.hash(user.password, salt, function(err, hash) {
      user.password = hash;
Example #17
0
/**
 * Round model.
 */

var _ = require('lodash');
var mongoose = require('mongoose');


exports.schema = RoundSchema = new mongoose.Schema({
  started : {
    type: Date,
    'default': Date.now,
    required: true
  }
});


/**
 * -------------------
 * Virtual attributes.
 * -------------------
 */


/**
 * Get id.
 *
 * @return {String}: The id.
 */
RoundSchema.virtual('id').get(function() {
 */
var mongoose = require('mongoose');
var async = require('async');

var schema = new mongoose.Schema({
	uid: String, //** 用户Id
	username: String, //** 用户姓名
	mobile: String, //** 用户手机号
	bankName: String, //** 银行名称
	bankCode: String, //** 银行代码
	bankAddr: String, //** 银行地址
	accountName: String, //** 银行卡姓名
	accountNo: String, //** 银行卡卡号
	cardId: String, //** 身份证号码
	expired: String, //** 有效期
	lastupdatetime: {
		type: Date,
		default: Date.now
	},
	status: {
		type: String,
		enum: {
			values: '新建|通过|放弃'.split('|'),
			message: 'enum validator failed for path {PATH} with value {VALUE}',
		}
	},
});

schema.set('collection', 'finance.banks.apply');

module.exports = exports = function(connection){
Example #19
0
var schema = new mongoose.Schema({
    email: {
        type: String
    },
    password: {
        type: String
    },
    salt: {
        type: String
    },
    twitter: {
        id: String,
        username: String,
        token: String,
        tokenSecret: String
    },
    facebook: {
        id: String
    },
    google: {
        id: String
    },
    github: {
        id: String,
        username: String,
        displayName: String,
        profileUrl: String,
        avatar: String,
        token: String
    },
    projects: {
        type: [{
            type: mongoose.Schema.ObjectId,
            ref: "Build"
        }]
    }
});
Example #20
0
var mongoose = require('mongoose');
var autoIncrement = require('mongoose-auto-increment');

var RouteSchema = new mongoose.Schema({
    departure: {type:String, require:true},
    arrival: {type:String, require:true},
    cost: Number,
    payment_type: String,
    departure_time: Date,
    contact: String,
    streets: Array,
    seats: Number,
    passengers: Array
});

RouteSchema.plugin(autoIncrement.plugin, {model: 'Route', field: 'id', startAt: 1});

module.exports = mongoose.model('Route', RouteSchema);
Example #21
0
var UserSchema = new Schema({
  name: String,
  email: {
    type: String,
    lowercase: true,
    required() {
      if(authTypes.indexOf(this.provider) === -1) {
        return true;
      } else {
        return false;
      }
    }
  },
  role: {
    type: String,
    default: 'user'
  },
  password: {
    type: String,
    required: function() {
      if(authTypes.indexOf(this.provider) === -1) {
        return true;
      } else {
        return false;
      }
    }
  },
  provider: String,
  salt: String,
  facebook: {},
  twitter: {},
  google: {},
  github: {}
});
Example #22
0
var mongoose = require('mongoose');
var autoIncrement = require('mongoose-auto-increment');

var tracking_schema = new mongoose.Schema({
    id: { type: Number },
    created_by: { type: Number },
    updated_by: { type: Number },
    updated_date: { type: Date, default: Date.now() },
    clicktale: { type: String },
    ecomm360: { type: Boolean },
    goal_tracking: { type: Boolean },
    google_analytics: { type: String },
    html_clicks: { type: Boolean },
    opens: { type: Boolean },
    text_clicks: { type: Boolean },
}, {
        versionKey: false

    });
autoIncrement.initialize(mongoose);
tracking_schema.plugin(autoIncrement.plugin, { model: 'tracking', startAt: 1 });
module.exports = mongoose.model('tracking', tracking_schema);
Example #23
0
File: user.js Project: jds8/Faneron
var unique_message = "It seems like someone's already used that {PATH}";

var userSchema = new mongoose.Schema({

	info: {
		firstName: { type: String, default: '' },
		lastName: { type: String, default: '' },
		username: { type: String, unique: true },
		email: { type: String, unique: true },
		password: { type: String, },
	},

	bio: { type: String, default: '' },

	rank: {
		currency: {type: Number, default: 0},
		xp: {type: Number, default: 0}
	},

	projects: [{
		type: Schema.Types.ObjectId,
		ref: 'Project'
	}],

	comments: [{
		type: Schema.Types.ObjectId,
		ref: 'Comment'
	}]
});

// Validations
Example #24
0
var config = require('config')
var mongoose = require('mongoose');

var expires = config.config.dbExpires

var LpnSchema = new mongoose.Schema({
  license_number: Number, 
  createdAt: Date,
  floor_id: String
});

LpnSchema.index({ "createdAt": 1 }, { expireAfterSeconds: expires });

mongoose.model('Lpn', LpnSchema);

var db = mongoose.connect('mongodb://localhost/lpn');

var Lpn = db.model('Lpn');
var time = new Date();

exports.save = function(license_number, createdAt, floor_id) {
  var record = new Lpn({
    license_number: license_number,
    createdAt, createdAt,
    floor_id: floor_id
  });
  record.save();
};

exports.find = function(license_number, fn) {
  Lpn.find({ license_number: license_number }, function(err, res) {
Example #25
0
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
var crypto = require('crypto');

var userSchema = new mongoose.Schema({
  email: { type: String, unique: true, lowercase: true },
  password: String,

  facebook: String,
  twitter: String,
  google: String,
  instagram: String,
  tokens: Array,

  profile: {
    name: { type: String, default: '' },
    gender: { type: String, default: '' },
    location: { type: String, default: '' },
    website: { type: String, default: '' },
    picture: { type: String, default: '' }
  },

  resetPasswordToken: String,
  resetPasswordExpires: Date
});

/**
 * Hash the password for security.
 * "Pre" is a Mongoose middleware that executes before each user.save() call.
 */
Example #26
0
'use strict';

var mongoose = require('mongoose');
var async = require('async');
var schema = new mongoose.Schema({
  'user'   : {
    'type'         : mongoose.Schema.Types.ObjectId,
    'ref'          : 'User',
    'required'     : true,
    'autopopulate' : true
  },
  'trophy' : {
    'type'     : String,
    'required' : true
  }
}, {
  'collection' : 'bets',
  'strict'     : true,
  'toJSON'     : {
    'virtuals' : true
  }
});

schema.index({'user' : 1, 'match' : 1}, {'unique' : true});

schema.plugin(require('mongoose-autopopulate'));
schema.plugin(require('mongoose-json-select'), {
  '_id'    : 1,
  'user'   : 1,
  'trophy' : 1
});
Example #27
0
// user.js - model to store user info when account CRUD

var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs'); // to encrypt passwords; never save as plain text

var UserSchema = new mongoose.Schema({
	username:{
		type:String,
		unique:true,
		required:true
	},
	password:{
		type:String,
		required:true
	}
});

UserSchema.pre('save',function(callback){
	var user = this;

	// break out if the password hasn't changed
	if (!user.isModified('password')) return callback();

	// password changed so we need to hash it
	bcrypt.genSalt(5,function(err,salt){
		if (err) return callback(err);

		bcrypt.hash(user.password, salt, null, function (err,hash){
			if (err) return callback(err);
			user.password = hash;
			callback();
Example #28
0
 * Created by 31491 on 2016/4/14.
 * Model Customers
 *
 */

'use strict';

const mongoose = require('mongoose');
const FN = require('../classes/functions.js');
const map = require('../configs/map.js');

const CustomerSchema = new mongoose.Schema({
    name: String,
    tel: String,
    town: Number,
    useful: Boolean,
    marks: String,
    join_time: Number,
    last_time: Number
});

CustomerSchema.virtual('text_town').get(function(){
    return map.town[this.town];
});

/*
 * @param start Number
 * @param end Nunber
 * @param cb Function
 * */
CustomerSchema.statics.getLists = function (param, start, count, cb) {
Example #29
0
var mongoose = require('mongoose')
var Schema = mongoose.Schema
var ObjectId = Schema.ObjectId

var CategorySchema = new mongoose.Schema({
	name:String
	,prop:Number
	,count:Number
    ,meta:{
        createAt:{
            type:Date,
            default:Date.now()
        },
        updateAt:{
            type:Date,
            default:Date.now()
        }

    }
})

CategorySchema.pre('save',function(next){
    if (this.isNew){
        this.meta.createAt = this.meta.updateAt = Date.now()
    } else {
        this.meta.updateAt = Date.now()
    }
    next()
})

CategorySchema.statics = {
var solicitationSchema = new mongoose.Schema({
    id: ObjectId,
    title: String,
    author: String,
    description: String,
    type: String,
    comments: [
        { body: String, date: Date }
    ],
    tags: [
        { tag: String }
    ],
    hidden: Boolean,
    meta: {
        votes: Number,
        favs: Number
    },
    address: {
        "address_components": [
            {
                "long_name": String,
                "short_name": String,
                "types": Array
            }
        ],
        "location": [Number]  // [lng, lat]
    },
    audit: {
        createdAt: { type: Date, default: Date.now },
        lastModifiedAt: { type: Date, default: Date.now }
    }
});