Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Error when user roles is missing or is invalid #9040

Merged
merged 3 commits into from Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Expand Up @@ -663,6 +663,7 @@
"error-the-field-is-required": "The field __field__ is required.",
"error-too-many-requests": "Error, too many requests. Please slow down. You must wait __seconds__ seconds before trying again.",
"error-user-is-not-activated": "User is not activated",
"error-user-has-no-roles": "User has no roles",
"error-user-limit-exceeded": "The number of users you are trying to invite to #channel_name exceeds the limit set by the administrator",
"error-user-not-in-room": "User is not in this room",
"error-user-registration-disabled": "User registration is disabled",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Expand Up @@ -452,6 +452,7 @@
"error-the-field-is-required": "O campo __field__ é obrigatório.",
"error-too-many-requests": "Erro, muitas solicitações. Por favor, diminua a velocidade. Você deve esperar __seconds__ segundos antes de tentar novamente.",
"error-user-is-not-activated": "O usuário não está ativo",
"error-user-has-no-roles": "O usuário não possui permissões",
"error-user-not-in-room": "O usuário não está nesta sala",
"error-user-registration-disabled": "O registro do usuário está desativado",
"error-user-registration-secret": "O registro de usuário é permitido somente via URL secreta",
Expand Down
6 changes: 6 additions & 0 deletions server/lib/accounts.js
Expand Up @@ -176,6 +176,12 @@ Accounts.validateLoginAttempt(function(login) {
});
}

if (!login.user.roles || !Array.isArray(login.user.roles)) {
throw new Meteor.Error('error-user-has-no-roles', 'User has no roles', {
'function': 'Accounts.validateLoginAttempt'
});
}

if (login.user.roles.includes('admin') === false && login.type === 'password' && RocketChat.settings.get('Accounts_EmailVerification') === true) {
const validEmail = login.user.emails.filter(email => email.verified === true);
if (validEmail.length === 0) {
Expand Down