diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
commit | 69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd (patch) | |
tree | 8659f819818a3da6419959b6b7838a7f0557c948 /server/models/user.js | |
parent | a3ee6fa22dee4b68fcde9cd23708b471db446e11 (diff) | |
download | PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.gz PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.zst PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.zip |
OAuth/User models refractoring -> use mongoose api
Diffstat (limited to 'server/models/user.js')
-rw-r--r-- | server/models/user.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/server/models/user.js b/server/models/user.js new file mode 100644 index 000000000..130b49b55 --- /dev/null +++ b/server/models/user.js | |||
@@ -0,0 +1,28 @@ | |||
1 | const mongoose = require('mongoose') | ||
2 | |||
3 | // --------------------------------------------------------------------------- | ||
4 | |||
5 | const UserSchema = mongoose.Schema({ | ||
6 | password: String, | ||
7 | username: String | ||
8 | }) | ||
9 | |||
10 | UserSchema.path('password').required(true) | ||
11 | UserSchema.path('username').required(true) | ||
12 | |||
13 | UserSchema.statics = { | ||
14 | list: list, | ||
15 | loadByUsernameAndPassword: loadByUsernameAndPassword | ||
16 | } | ||
17 | |||
18 | mongoose.model('User', UserSchema) | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | function list (callback) { | ||
23 | return this.find(callback) | ||
24 | } | ||
25 | |||
26 | function loadByUsernameAndPassword (username, password, callback) { | ||
27 | return this.findOne({ username: username, password: password }, callback) | ||
28 | } | ||