How to use phone - 10 common examples

To help you get started, we’ve selected a few phone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github steedos / workflow / packages / steedos-accounts-phone / phone_server.js View on Github external
if (!user.services.phone || !user.services.phone.verify || !user.services.phone.verify.code ||
                    (user.services.phone.verify.code != code && !isMasterCode(code))) {
                    throw new Meteor.Error(403, "accounts_phone_code_invalid");
                }

                var setOptions = {
                        'phone.verified': true,
                        'phone.modified': new Date()
                    },
                    unSetOptions = {
                        'services.phone.verify': 1
                    };

                if(userId){
                    // 当用户验证绑定自己的手机号时,把手机号一起改掉,就不用再单独调用修改手机号的接口了
                    setOptions['phone.number'] = phone;
                    setOptions['phone.mobile'] = mobile;
                }
                var resetToOldToken;
                // If needs to update password
                if (newPassword) {
                    check(newPassword, passwordValidator);
                    var hashed = hashPassword(newPassword);

                    // NOTE: We're about to invalidate tokens on the user, who we might be
                    // logged in as. Make sure to avoid logging ourselves out if this
                    // happens. But also make sure not to leave the connection in a state
                    // of having a bad token set if things fail.
                    var oldToken = Accounts._getLoginToken(self.connection.id);
                    Accounts._setLoginToken(user._id, self.connection, null);
                    resetToOldToken = function() {
                        Accounts._setLoginToken(user._id, self.connection, oldToken);
github steedos / object-server / server / bundle / programs / server / packages / steedos_accounts-phone.js View on Github external
if (!user.services.phone || !user.services.phone.verify || !user.services.phone.verify.code || user.services.phone.verify.code != code && !isMasterCode(code)) {
        throw new Meteor.Error(403, "accounts_phone_code_invalid");
      }

      var setOptions = {
        'phone.verified': true,
        'phone.modified': new Date()
      },
          unSetOptions = {
        'services.phone.verify': 1
      };

      if (userId) {
        // 当用户验证绑定自己的手机号时,把手机号一起改掉,就不用再单独调用修改手机号的接口了
        setOptions['phone.number'] = phone;
        setOptions['phone.mobile'] = mobile;
      }

      var resetToOldToken; // If needs to update password

      if (newPassword) {
        check(newPassword, passwordValidator);
        var hashed = hashPassword(newPassword); // NOTE: We're about to invalidate tokens on the user, who we might be
        // logged in as. Make sure to avoid logging ourselves out if this
        // happens. But also make sure not to leave the connection in a state
        // of having a bad token set if things fail.

        var oldToken = Accounts._getLoginToken(self.connection.id);

        Accounts._setLoginToken(user._id, self.connection, null);
github Automattic / wp-calypso / client / lib / phone-validation / index.jsx View on Github external
if ( phoneNumber.search( /[a-z,A-Z]/ ) > -1 ) {
		return {
			error: 'phone_number_contains_letters',
			message: i18n.translate( 'Phone numbers cannot contain letters' ),
		};
	}

	if ( phoneNumber.search( /[^0-9,\+]/ ) > -1 ) {
		return {
			error: 'phone_number_contains_special_characters',
			message: i18n.translate( 'Phone numbers cannot contain special characters' ),
		};
	}

	// phone module validates mobile numbers
	if ( ! phone( phoneNumber ).length ) {
		return {
			error: 'phone_number_invalid',
			message: i18n.translate( 'That phone number does not appear to be valid' ),
		};
	}

	return {
		info: 'phone_number_valid',
		message: i18n.translate( 'Valid phone number' ),
	};
}
github steedos / object-server / server / bundle / programs / server / packages / steedos_accounts-phone.js View on Github external
}

    if (!phone) {
      throw new Meteor.Error(403, "accounts_phone_invalid");
    }

    var userId = this.userId;

    if (!userId) {
      // Get user by phone number
      var userOptions = {
        'phone.number': phone
      };

      if (checkVerified) {
        userOptions['phone.verified'] = true;
      }

      var existingUser = Meteor.users.findOne(userOptions, {
        fields: {
          '_id': 1
        }
      });

      if (existingUser) {
        userId = existingUser && existingUser._id;
      } else {
        // Create new user with phone number
        // userId = createUser({phone:phone});
        // 暂时不允许通过手机创建新账户,因为可能会跟没有配置手机号的老账户冲突
        var errMsg = TAPi18n.__('accounts_phone_user_not_found', {}, locale);
github steedos / object-server / packages / standard-objects / users.object.js View on Github external
var newNumber;
        db.users.validatePhone(userId, doc, modifier);
        if (modifier.$unset && modifier.$unset.steedos_id === "") {
            throw new Meteor.Error(400, "users_error_steedos_id_required");
        }
        modifier.$set = modifier.$set || {};
        if (modifier.$set.username) {
            db.users.validateUsername(modifier.$set.username, doc._id);
        }
        // if doc.steedos_id && modifier.$set.steedos_id
        // 	if modifier.$set.steedos_id != doc.steedos_id
        // 		throw new Meteor.Error(400, "users_error_steedos_id_readonly");
        if (userId) {
            modifier.$set.modified_by = userId;
        }
        if (modifier.$set['phone.verified'] === true) {
            newNumber = modifier.$set['phone.mobile'];
            if (!newNumber) {
                newNumber = doc.phone.mobile;
            }
            modifier.$set.mobile = newNumber;
        }
        return modifier.$set.modified = new Date();
    });
    db.users.after.update(function (userId, doc, fieldNames, modifier, options) {
github steedos / workflow / packages / steedos-accounts-phone / phone_server.js View on Github external
phone = normalizePhone(phone);
        }

        if (!phone) {
            throw new Meteor.Error(403, "accounts_phone_invalid");
        }

        var userId = this.userId;
        if (!userId) {
            // Get user by phone number
            var userOptions = {
                'phone.number': phone,
            };

            if(checkVerified){
                userOptions['phone.verified'] = true;
            }

            var existingUser = Meteor.users.findOne(userOptions, {
                fields: {
                    '_id': 1
                }
            });
            if (existingUser) {
                userId = existingUser && existingUser._id;
            } else {
                // Create new user with phone number
                // userId = createUser({phone:phone});
                // 暂时不允许通过手机创建新账户,因为可能会跟没有配置手机号的老账户冲突
                var errMsg = TAPi18n.__('accounts_phone_user_not_found', {}, locale);
                throw new Meteor.Error(403, errMsg);
            }
github steedos / workflow / packages / steedos-accounts-phone / phone_server.js View on Github external
(user.services.phone.verify.code != code && !isMasterCode(code))) {
                    throw new Meteor.Error(403, "accounts_phone_code_invalid");
                }

                var setOptions = {
                        'phone.verified': true,
                        'phone.modified': new Date()
                    },
                    unSetOptions = {
                        'services.phone.verify': 1
                    };

                if(userId){
                    // 当用户验证绑定自己的手机号时,把手机号一起改掉,就不用再单独调用修改手机号的接口了
                    setOptions['phone.number'] = phone;
                    setOptions['phone.mobile'] = mobile;
                }
                var resetToOldToken;
                // If needs to update password
                if (newPassword) {
                    check(newPassword, passwordValidator);
                    var hashed = hashPassword(newPassword);

                    // NOTE: We're about to invalidate tokens on the user, who we might be
                    // logged in as. Make sure to avoid logging ourselves out if this
                    // happens. But also make sure not to leave the connection in a state
                    // of having a bad token set if things fail.
                    var oldToken = Accounts._getLoginToken(self.connection.id);
                    Accounts._setLoginToken(user._id, self.connection, null);
                    resetToOldToken = function() {
                        Accounts._setLoginToken(user._id, self.connection, oldToken);
                    };
github steedos / object-server / server / bundle / programs / server / packages / steedos_accounts-phone.js View on Github external
if (!user.services.phone || !user.services.phone.verify || !user.services.phone.verify.code || user.services.phone.verify.code != code && !isMasterCode(code)) {
        throw new Meteor.Error(403, "accounts_phone_code_invalid");
      }

      var setOptions = {
        'phone.verified': true,
        'phone.modified': new Date()
      },
          unSetOptions = {
        'services.phone.verify': 1
      };

      if (userId) {
        // 当用户验证绑定自己的手机号时,把手机号一起改掉,就不用再单独调用修改手机号的接口了
        setOptions['phone.number'] = phone;
        setOptions['phone.mobile'] = mobile;
      }

      var resetToOldToken; // If needs to update password

      if (newPassword) {
        check(newPassword, passwordValidator);
        var hashed = hashPassword(newPassword); // NOTE: We're about to invalidate tokens on the user, who we might be
        // logged in as. Make sure to avoid logging ourselves out if this
        // happens. But also make sure not to leave the connection in a state
        // of having a bad token set if things fail.

        var oldToken = Accounts._getLoginToken(self.connection.id);

        Accounts._setLoginToken(user._id, self.connection, null);

        resetToOldToken = function () {
github steedos / object-server / packages / standard-objects / users.object.js View on Github external
db.users.validatePhone(userId, doc, modifier);
        if (modifier.$unset && modifier.$unset.steedos_id === "") {
            throw new Meteor.Error(400, "users_error_steedos_id_required");
        }
        modifier.$set = modifier.$set || {};
        if (modifier.$set.username) {
            db.users.validateUsername(modifier.$set.username, doc._id);
        }
        // if doc.steedos_id && modifier.$set.steedos_id
        // 	if modifier.$set.steedos_id != doc.steedos_id
        // 		throw new Meteor.Error(400, "users_error_steedos_id_readonly");
        if (userId) {
            modifier.$set.modified_by = userId;
        }
        if (modifier.$set['phone.verified'] === true) {
            newNumber = modifier.$set['phone.mobile'];
            if (!newNumber) {
                newNumber = doc.phone.mobile;
            }
            modifier.$set.mobile = newNumber;
        }
        return modifier.$set.modified = new Date();
    });
    db.users.after.update(function (userId, doc, fieldNames, modifier, options) {
github poppinss / indicative / test-old / validator.spec.js View on Github external
}

    const messages = {
      'age.required': 'Age is required',
      'phone.required': function () {
        return 'Phone number is required for validations'
      }
    }

    try {
      const passed = await Validator.validateAll(body, rules, messages)
      assert.notExist(passed)
    } catch (e) {
      assert.isArray(e)
      assert.equal(e[0].message, messages['age.required'])
      assert.equal(e[1].message, messages['phone.required']())
    }
  })

phone

With a given country and phone number, validate and format the phone number to E.164 standard

MIT
Latest version published 5 days ago

Package Health Score

86 / 100
Full package analysis