Lang for oauth users

This commit is contained in:
vjrj 2018-02-12 19:52:22 +01:00
parent 47b55267df
commit 08b3289f4d
6 changed files with 42 additions and 25 deletions

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

View file

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