Skip to content

Commit fdf0427

Browse files
author
nizyev
committed
github account email extract
1 parent 2d3492d commit fdf0427

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

server/accounts.coffee

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
Accounts.onCreateUser (options, user) ->
2-
profileImageUrl = undefined
3-
user.profile = user.profile or {}
2+
profileImageUrl = undefined
3+
user.profile = user.profile or {}
44

5-
if user.services?.facebook
6-
user.emails = [{address: user.services.facebook.email, verified: true}]
7-
user.profile.firstName = user.services.facebook.first_name
8-
user.profile.lastName = user.services.facebook.last_name
9-
if user.services?.google
10-
user.emails = [{address: user.services.google.email, verified: true}]
11-
user.profile.firstName = user.services.google.given_name
12-
user.profile.lastName = user.services.google.family_name
13-
# TODO: twitter email, first name and last name
5+
if user.services?.facebook
6+
user.emails = [{address: user.services.facebook.email, verified: true}]
7+
user.profile.firstName = user.services.facebook.first_name
8+
user.profile.lastName = user.services.facebook.last_name
9+
if user.services?.google
10+
user.emails = [{address: user.services.google.email, verified: true}]
11+
user.profile.firstName = user.services.google.given_name
12+
user.profile.lastName = user.services.google.family_name
13+
if user.services?.github
14+
user.emails = [{address: user.services.github.email, verified: true}]
1415

15-
if user.services?.facebook?.id
16-
profileImageUrl = 'https://graph.facebook.com/v2.3/' + user.services.facebook.id + '/picture?type=normal'
17-
if user.services?.google?.id
18-
profileImageUrl = user.services.google.picture
19-
if user.services?.twitter?.id
20-
profileImageUrl = user.services.twitter.profile_image_url
16+
if user.services?.facebook?.id
17+
profileImageUrl = 'https://graph.facebook.com/v2.3/' + user.services.facebook.id + '/picture?type=normal'
18+
if user.services?.google?.id
19+
profileImageUrl = user.services.google.picture
20+
if user.services?.twitter?.id
21+
profileImageUrl = user.services.twitter.profile_image_url
22+
if user.services?.github?.id
23+
profileImageUrl = user.services.github.avatar_url
2124

22-
if not profileImageUrl
23-
# Try and get via Gravatar
24-
# Gravatar currently always returns an image, whether the user set one or not.
25-
# It's possible to set {default: 404} and then detect a 404 status via HTTP request
26-
# This could increase the time needed to create a new user so it's avoided for now
27-
#
28-
# TODO: Set default profile picture in config. If 'null' then field is left blank
25+
if not profileImageUrl
26+
# Try and get via Gravatar
27+
# Gravatar currently always returns an image, whether the user set one or not.
28+
# It's possible to set {default: 404} and then detect a 404 status via HTTP request
29+
# This could increase the time needed to create a new user so it's avoided for now
30+
#
31+
# TODO: Set default profile picture in config. If 'null' then field is left blank
2932

30-
email = user.emails?[0]?.address or ''
31-
profileImageUrl = Gravatar.imageUrl email, {default: 'identicon'}
33+
email = user.emails?[0]?.address or ''
34+
profileImageUrl = Gravatar.imageUrl email, {default: 'identicon'}
3235

33-
if profileImageUrl
34-
picture = new FS.File()
35-
attachData = Meteor.wrapAsync picture.attachData, picture
36-
attachData profileImageUrl
37-
picture.name('picture ' + user._id + '.png')
38-
profilePicture = ProfilePictures.insert picture
39-
user.profile.picture = profilePicture._id
40-
41-
user
36+
if profileImageUrl
37+
picture = new FS.File()
38+
attachData = Meteor.wrapAsync picture.attachData, picture
39+
attachData profileImageUrl
40+
picture.name('picture ' + user._id + '.png')
41+
profilePicture = ProfilePictures.insert picture
42+
user.profile.picture = profilePicture._id
43+
44+
user

0 commit comments

Comments
 (0)