Added user lang setting

This commit is contained in:
vjrj 2018-01-09 12:05:36 +01:00
parent fc56bd3273
commit 97c47c5d1d
7 changed files with 90 additions and 21 deletions

View file

@ -1,9 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { check, Match } from 'meteor/check';
import { Accounts } from 'meteor/accounts-base';
import editProfile from './edit-profile';
import rateLimit from '../../../modules/rate-limit';
const validLangCode = Match.Where((lang) => {
check(lang, String);
const regexp = /^[a-z]{2,3}(?:-[A-Z]{2,3}(?:-[a-zA-Z]{4})?)?$/;
return regexp.test(lang);
});
Meteor.methods({
'users.sendVerificationEmail': function usersSendVerificationEmail() {
return Accounts.sendVerificationEmail(this.userId);
@ -14,24 +20,28 @@ Meteor.methods({
profile: {
name: {
first: String,
last: String,
},
},
last: String
}
}
});
return editProfile({ userId: this.userId, profile })
.then(response => response)
.catch((exception) => {
throw new Meteor.Error('500', exception);
});
.then(response => response)
.catch((exception) => {
throw new Meteor.Error('500', exception);
});
},
'users.setLang': function userLang(lang) {
check(lang, validLangCode);
Meteor.users.update({ _id: this.userId }, { $set: { lang } });
}
});
rateLimit({
methods: [
'users.sendVerificationEmail',
'users.editProfile',
'users.editProfile'
],
limit: 5,
timeRange: 1000,
timeRange: 1000
});