Lang for oauth users
This commit is contained in:
parent
47b55267df
commit
08b3289f4d
6 changed files with 42 additions and 25 deletions
|
|
@ -10,11 +10,12 @@ export default (options, user, lang) => {
|
|||
const applicationName = i18n.t('AppName');
|
||||
const firstName = OAuthProfile ? OAuthProfile.name.first : options.profile.name.first;
|
||||
const emailAddress = OAuthProfile ? OAuthProfile.email : options.email;
|
||||
const welcome = i18n.t('welcome');
|
||||
if (emailAddress) {
|
||||
sendEmail({
|
||||
to: emailAddress,
|
||||
from: `${applicationName} <noreply@comunes.org>`,
|
||||
subject: `[${applicationName}] Welcome, ${firstName}!`,
|
||||
subject: `[${applicationName}] ${welcome} ${firstName}!`,
|
||||
lang,
|
||||
template: 'welcome',
|
||||
templateVars: {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
const parseGoogleData = service => {
|
||||
return {
|
||||
email: service.email,
|
||||
name: {
|
||||
first: service.given_name,
|
||||
last: service.family_name,
|
||||
},
|
||||
};
|
||||
};
|
||||
const parseGoogleData = service => ({
|
||||
email: service.email,
|
||||
name: {
|
||||
first: service.given_name,
|
||||
last: service.family_name
|
||||
},
|
||||
lang: service.locale
|
||||
});
|
||||
|
||||
const parseGithubData = (profile, service) => {
|
||||
const name = profile.name.split(' ');
|
||||
|
|
@ -14,20 +13,18 @@ const parseGithubData = (profile, service) => {
|
|||
email: service.email,
|
||||
name: {
|
||||
first: name[0],
|
||||
last: name[1],
|
||||
},
|
||||
last: name[1]
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const parseFacebookData = service => {
|
||||
return {
|
||||
email: service.email,
|
||||
name: {
|
||||
first: service.first_name,
|
||||
last: service.last_name,
|
||||
},
|
||||
};
|
||||
};
|
||||
const parseFacebookData = service => ({
|
||||
email: service.email,
|
||||
name: {
|
||||
first: service.first_name,
|
||||
last: service.last_name
|
||||
}
|
||||
});
|
||||
|
||||
const getDataForService = (profile, services) => {
|
||||
if (services.facebook) return parseFacebookData(services.facebook);
|
||||
|
|
|
|||
8
imports/startup/server/accounts/lang-fallback.js
Normal file
8
imports/startup/server/accounts/lang-fallback.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
const getFallbackLang = (lang) => {
|
||||
if (lang && (lang === 'ast' || lang === 'gl' || lang === 'eu' || lang === 'ca' || lang.match(/^es/))) {
|
||||
return 'es';
|
||||
}
|
||||
return 'en';
|
||||
};
|
||||
|
||||
export default getFallbackLang;
|
||||
|
|
@ -1,18 +1,25 @@
|
|||
import { Accounts } from 'meteor/accounts-base';
|
||||
import sendWelcomeEmail from '../../../api/Users/server/send-welcome-email';
|
||||
import getOAuthProfile from '../../../modules/get-oauth-profile';
|
||||
import getFallbackLang from './lang-fallback';
|
||||
|
||||
Accounts.onCreateUser((options, user) => {
|
||||
const userToCreate = user;
|
||||
// console.log(JSON.stringify(user));
|
||||
// console.log(JSON.stringify(options));
|
||||
|
||||
let lang = 'en'; // fallback
|
||||
if (options.profile) {
|
||||
userToCreate.profile = options.profile;
|
||||
userToCreate.lang = options.profile.lang;
|
||||
lang = options.profile.lang;
|
||||
// console.log(JSON.stringify(user));
|
||||
lang = userToCreate.lang;
|
||||
delete options.profile.lang;
|
||||
} else {
|
||||
// TODO others (google, etc) ?
|
||||
}
|
||||
const OAuthProfile = getOAuthProfile(options, user);
|
||||
if (OAuthProfile) {
|
||||
userToCreate.lang = getFallbackLang(OAuthProfile && OAuthProfile.lang ? OAuthProfile.lang : lang);
|
||||
lang = userToCreate.lang;
|
||||
}
|
||||
sendWelcomeEmail(options, userToCreate, lang);
|
||||
return userToCreate;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue