You are here

function sms_receive_authenticate in SMS Framework 5

Loosely based on mailhandler_authenticate() Determine who is the author of the upcoming node.

1 call to sms_receive_authenticate()
sms_receive_receive in modules/sms_receive/sms_receive.module

File

modules/sms_receive/sms_receive.module, line 241

Code

function sms_receive_authenticate($node, $sms_message) {

  // is $sms_message['from'] a general case?
  $number = $sms_message['from'];

  // how is this be handled with international numbers? do we need to remove +44 for UK?
  // should be able to test when we get Chinese SIM card
  if (substr($number, 0, 1) == '1') {

    // remove leading '1', sms_user doesn't store it...
    $number = substr($number, 1);
  }

  // This is much cleaner, but might still be nice to use a table with phone numbers
  // ie. could query: SELECT uid FROM {sms_user} WHERE 'number' = 7785555555
  $result = db_query("SELECT uid, name FROM {users} WHERE data LIKE '%" . $number . "%'");
  while ($account = db_fetch_object($result)) {
    $node->uid = $account->uid;
    $node->name = $account->name;
    break;
  }

  // Set to anonymous if no match
  if (empty($node->uid) && empty($node->name)) {
    $node->uid = 0;
    $node->name = '';
  }
  return $node;
}