summaryrefslogtreecommitdiff
path: root/server/lib/schemas/User.js
blob: 1441631578c7950016660784ee40243b739fcc6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* jshint node: true */

var NONALPHANUMERICS_REGEX = new RegExp('[^-_a-zA-Z0-9]', 'g')

var mongoose = require('mongoose'),
	_ = require('lodash'),
	config = require('../../../config.json');

var UserSchema = new mongoose.Schema({
	twitter_id: String,
	displayName: String,
	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 '':
					return false
			}
			if (! this.displayName) { this.displayName = val; }
			return true
		}, "{PATH} is not an acceptable name"]
	},
	email: {
		type: String,
		default: "",
	},
	emailVerified: {
		type: Boolean,
		default: false,
	},
	password: {
		type: String,
		validate: [function (val) {
			if (! val.length) return true
			return true
		}, "{PATH} is not an acceptable password"]
	},
	photo: {
		type: String,
		required: true
	},
	bio: {
		type: String,
		default: ""
	},
	links: [
		{ type: String, default: "" }
	],
	isAdmin: { type: Boolean, default: false }
});


module.exports = exports = mongoose.model('user', UserSchema);
exports.schema = UserSchema;