Skip to content

Commit

Permalink
Add phone number validation via google-libphonenumber
Browse files Browse the repository at this point in the history
  • Loading branch information
kb0304 committed Dec 29, 2018
1 parent bb1df01 commit cf1b023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "Rocket.Chat",
"description": "The Ultimate Open Source WebChat Platform",
"version": "0.73.0-develop",

"author": {
"name": "Rocket.Chat",
"url": "https://rocket.chat/"
Expand Down Expand Up @@ -151,6 +150,7 @@
"fibers": "^3.1.1",
"file-type": "^10.6.0",
"filesize": "^3.6.1",
"google-libphonenumber": "3.2.1",
"grapheme-splitter": "^1.0.4",
"gridfs-stream": "^1.1.1",
"he": "^1.2.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat } from 'meteor/rocketchat:lib';
import { PhoneNumberUtil } from 'google-libphonenumber';

const phoneUtil = PhoneNumberUtil.getInstance();

RocketChat.API.v1.addRoute('info', { authRequired: false }, {
get() {
Expand Down Expand Up @@ -202,6 +205,10 @@ RocketChat.API.v1.addRoute('invite.sms', { authRequired: true }, {
throw new Meteor.Error('error-phone-param-not-provided', 'The required "phone" param is required.');
}
const phone = this.bodyParams.phone.replace(/-|\s/g, '');
if (!phoneUtil.isValidNumber(phoneUtil.parse(phone))) {
return RocketChat.API.v1.failure('Invalid number');
}

const result = Meteor.runAsUser(this.userId, () => Meteor.call('sendInvitationSMS', [phone]));
if (result.indexOf(phone) >= 0) {
return RocketChat.API.v1.success();
Expand Down

0 comments on commit cf1b023

Please sign in to comment.