Move auth functions to central location

This commit is contained in:
Berkeley Martinez
2015-08-12 12:15:19 -07:00
parent 49e9d078f1
commit a4e220e2bc
3 changed files with 49 additions and 80 deletions

View File

@@ -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;