aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user.js
blob: 130b49b55268cbc4d60705d3081a61a665aef83d (plain) (blame)
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
const mongoose = require('mongoose')

// ---------------------------------------------------------------------------

const UserSchema = mongoose.Schema({
  password: String,
  username: String
})

UserSchema.path('password').required(true)
UserSchema.path('username').required(true)

UserSchema.statics = {
  list: list,
  loadByUsernameAndPassword: loadByUsernameAndPassword
}

mongoose.model('User', UserSchema)

// ---------------------------------------------------------------------------

function list (callback) {
  return this.find(callback)
}

function loadByUsernameAndPassword (username, password, callback) {
  return this.findOne({ username: username, password: password }, callback)
}