Lang for oauth users
This commit is contained in:
parent
47b55267df
commit
08b3289f4d
6 changed files with 42 additions and 25 deletions
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