-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathusers.class.js
More file actions
36 lines (33 loc) · 1.18 KB
/
Copy pathusers.class.js
File metadata and controls
36 lines (33 loc) · 1.18 KB
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
// This is the database adapter service class
const { Service } = require('feathers-nedb');
// We need this to create the MD5 hash
const crypto = require('crypto');
// The Gravatar image service
const gravatarUrl = 'https://s.gravatar.com/avatar';
// The size query. Our chat needs 60px images
const query = 's=60';
// Returns the Gravatar image for an email
const getGravatar = email => {
// Gravatar uses MD5 hashes from an email address (all lowercase) to get the image
const hash = crypto.createHash('md5').update(email.toLowerCase()).digest('hex');
// Return the full avatar URL
return `${gravatarUrl}/${hash}?${query}`;
};
exports.Users = class Users extends Service {
create (data, params) {
// This is the information we want from the user signup data
const { email, password, githubId, name } = data;
// Use the existing avatar image or return the Gravatar for the email
const avatar = data.avatar || getGravatar(email);
// The complete user
const userData = {
email,
name,
password,
githubId,
avatar
};
// Call the original `create` method with existing `params` and new data
return super.create(userData, params);
}
};