A request from Be Hood http://groups.drupal.org/node/82444 was to be able to assign a role for a user who validated its mobile number.

The solution I thin it the appropriate one is adding a Rules event.
Since we don't want to force Rules module as part of the sms_user, the event is being triggered only if module_exists('rules').

Patch attached, seems to fit to both 6.x-1.x-dev and 6.x-2.x-dev.

Comments are welcome,
Shushu

Comments

shushu’s picture

Status: Active » Needs review
grub3’s picture

StatusFileSize
new1.23 KB

An updated version of the patch.

grub3’s picture

Status: Needs review » Reviewed & tested by the community

This patch works great, many thanks. This can solve spam issues. When a user validates the mobile phone number, he is assigned a group "Foo". Then I filter on "Foo" to allow posting messages. Great.

Setting to reviewed from the community.
Please apply ASAP.

grub3’s picture

What happens when a validated mobile phone is removed from user settings? Is there a way to trigger another action to remove user from role?

grub3’s picture

Okay, quite simple, I added the following code:

/*
* Implementation of hook_rules_event_info().
* @ingroup rules
 */
 function sms_user_rules_event_info() {
  return array(
    'sms_user_validated' => array(
      'label' => t('User validated SMS code'),
      'module' => 'SMS',
      'arguments' => array(
        'user' => array('type' => 'user', 'label' => t('Validated user')),
      ),
    ),
    'sms_user_removed' => array(
      'label' => t('User removed mobile phone number'),
      'module' => 'SMS',
      'arguments' => array(
        'user' => array('type' => 'user', 'label' => t('Removed mobile phone number')),
      ),
    ),
  );
}

AND:

function sms_user_settings_confirm_form_submit($form, &$form_state) {
  $account = user_load(array('uid' => arg(1)));
  if ($form_state['clicked_button']['#value'] == t('Delete & start over')) {
    sms_user_delete($account->uid);
  }
  else {
    $data = array(
      'number'  => $account->sms_user['number'],
      'status'  => SMS_USER_CONFIRMED,
      'gateway' => $account->sms_user['gateway'],
    );

    user_save($account, array('sms_user' => $data), 'mobile');
  }
  if (module_exists('rules')) {
      rules_invoke_event('sms_user_removed', $account);
  }
}
grub3’s picture

I would like to discuss the creation of a user right to delete a mobile phone number. To fight against SPAM one important issue is to make sure that users do not create multiple accounts. So binding a mobile phone against ONE single account is important. I will get back with some code. If we can discuss and work on these issues, this would be nice.

univate’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Reviewed & tested by the community » Needs work

Sounds like a great feature, lets have new developments against 2.x and get the additional rule for removing sms in there as well to complete the feature.

grub3’s picture

Status: Needs review » Needs work

Please find attached an updated patch, which invokes two rules:
* one upon SMS validation,
* one upon deletion.

You only have to edit the corresponding rules and apply a group, for example "sms".
People with group "sms" may have special rights, i.e. post in forums, write documentation, etc ...

Also this patch adds a "Delete mobile" right, to avoid spam.
e.i. people registering a mobile phone cannot delete their own mobile phone without explicit right.
This avoids people sending 100 sms to spam and ruin you.

grub3’s picture

Status: Needs work » Needs review
StatusFileSize
new3.34 KB

This patch has been running for 2 months on a production server without noticable problem.

BenK’s picture

Subscribing

univate’s picture

Status: Needs work » Fixed

I have committed this. I have also moved the sms_user rules that are incorrectly part of sms.module to the sms_user module.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pareen’s picture

Is this patch in core module? Is it working?

Can anyone confirm?

shushu’s picture

pareen, this patch seems to be in the 6.x-2.x-dev release.
If you encounter any problem with it, you are welcome to contact me.
Regards,
Shushu

  • Commit e7a33c7 on 6.x-2.x, 8.x-1.x by univate:
    #864326 by grub3, shushu: Add Rules event for validating mobile number.