forked from bencodezen/vue-enterprise-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
42 lines (41 loc) · 957 Bytes
/
users.js
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
const _ = require('lodash')
module.exports = {
all: [
{
id: 1,
username: 'admin',
password: 'password',
name: 'Vue Master',
},
{
id: 2,
username: 'user1',
password: 'password',
name: 'User One',
},
].map((user) => {
return {
...user,
token: `valid-token-for-${user.username}`,
}
}),
authenticate({ username, password }) {
return new Promise((resolve, reject) => {
const matchedUser = this.all.find(
(user) => user.username === username && user.password === password
)
if (matchedUser) {
resolve(this.json(matchedUser))
} else {
reject(new Error('Invalid user credentials.'))
}
})
},
findBy(propertyName, value) {
const matchedUser = this.all.find((user) => user[propertyName] === value)
return this.json(matchedUser)
},
json(user) {
return user && _.omit(user, ['password'])
},
}