diff --git a/common/models/User-Identity.js b/common/models/User-Identity.js index 779ad2f48f..fe9f135b91 100644 --- a/common/models/User-Identity.js +++ b/common/models/User-Identity.js @@ -1,51 +1,14 @@ -import assign from 'object.assign'; import debugFactory from 'debug'; +import { + setProfileFromGithub, + getFirstImageFromProfile +} from '../../server/utils/auth'; + const debug = debugFactory('freecc:models:userIdent'); const { defaultProfileImage } = require('../utils/constantStrings.json'); -function getFirstImageFromProfile(profile) { - return profile && profile.photos && profile.photos[0] ? - profile.photos[0].value : - null; -} - -// using es6 argument destructing -function setProfileFromGithub( - user, - { - profileUrl: githubURL, - username - }, - { - id: githubId, - 'avatar_url': picture, - email: githubEmail, - 'created_at': joinedGithubOn, - blog: website, - location, - name - } -) { - return assign( - user, - { isGithubCool: true, isMigrationGrandfathered: false }, - { - name, - username: username.toLowerCase(), - location, - joinedGithubOn, - website, - picture, - githubId, - githubURL, - githubEmail, - githubProfile: githubURL - } - ); -} - export default function(UserIdent) { UserIdent.observe('before save', function(ctx, next) { var userIdent = ctx.currentInstance || ctx.instance; diff --git a/server/server.js b/server/server.js index bf0cb8c396..012c5ffd3f 100755 --- a/server/server.js +++ b/server/server.js @@ -10,11 +10,10 @@ var uuid = require('node-uuid'), path = require('path'), passportProviders = require('./passport-providers'); +var setProfileFromGithub = require('./utils/auth').setProfileFromGithub; var generateKey = require('loopback-component-passport/lib/models/utils').generateKey; -/** - * Create Express server. - */ + var app = loopback(); expressState.extend(app); @@ -44,41 +43,6 @@ passportConfigurator.setupModels({ userCredentialModel: app.models.userCredential }); -// using es6 argument destructing -function setProfileFromGithub( - user, - { - profileUrl: githubURL, - username - }, - { - id: githubId, - 'avatar_url': picture, - email: githubEmail, - 'created_at': joinedGithubOn, - blog: website, - location, - name - } -) { - return assign( - user, - { isGithubCool: true, isMigrationGrandfathered: false }, - { - name, - username: username.toLowerCase(), - location, - joinedGithubOn, - website, - picture, - githubId, - githubURL, - githubEmail, - githubProfile: githubURL - } - ); -} - var passportOptions = { emailOptional: true, profileToUser: function(provider, profile) { diff --git a/server/utils/auth.js b/server/utils/auth.js new file mode 100644 index 0000000000..fcbf198098 --- /dev/null +++ b/server/utils/auth.js @@ -0,0 +1,42 @@ +import assign from 'object.assign'; + +// using es6 argument destructing +export function setProfileFromGithub( + user, + { + profileUrl: githubURL, + username + }, + { + id: githubId, + 'avatar_url': picture, + email: githubEmail, + 'created_at': joinedGithubOn, + blog: website, + location, + name + } +) { + return assign( + user, + { isGithubCool: true, isMigrationGrandfathered: false }, + { + name, + username: username.toLowerCase(), + location, + joinedGithubOn, + website, + picture, + githubId, + githubURL, + githubEmail, + githubProfile: githubURL + } + ); +} + +export function getFirstImageFromProfile(profile) { + return profile && profile.photos && profile.photos[0] ? + profile.photos[0].value : + null; +}