/* jshint node: true */ var NONALPHANUMERICS_REGEX = new RegExp('[^-_a-zA-Z0-9]', 'g') var mongoose = require('mongoose'), _ = require('lodash'), crypto = require('crypto'), config = require('../../../config.json'); var UserSchema = new mongoose.Schema({ twitter_id: String, facebook_id: String, displayName: { type: String, default: "" }, username: { type: String, required: true, validate: [function (val) { val = val.replace(NONALPHANUMERICS_REGEX, "") this.username = val.toLowerCase() switch (val) { case 'login': case 'logout': case 'profile': case 'auth': case 'upload': case 'about': case 'settings': case 'assets': case 'admin': case 'terms': case 'api': case 'vvalls': case 'assets': case '': return false } if (! this.displayName) { this.displayName = val; } return true }, "{PATH} is not an acceptable name"] }, email: { type: String, efault: "" }, emailVerified: { type: Boolean, default: false, }, password: { type: String, validate: [function (val) { if (! val.length) return true return true }, "{PATH} is not an acceptable password"] }, location: { type: String, default: "" }, photo: { type: String, default: "" }, bio: { type: String, default: "" }, website: { type: String, default: "" }, twitterName: { type: String, default: "" }, facebookUrl: { type: String, default: "" }, isAdmin: { type: Boolean, default: false } }); UserSchema.methods.validPassword = function (pw) { var shasum = crypto.createHash('sha1') shasum.update(pw) return this.password === shasum.digest('hex'); } module.exports = exports = mongoose.model('user', UserSchema); exports.schema = UserSchema;