示例#1
0
 /**
  * Sends a confirmation to the address given
  *
  * Stores a confirmation record and sends out a
  * Jabber message with the confirmation info.
  *
  * @return void
  */
 function addAddress()
 {
     $user = common_current_user();
     $jabber = $this->trimmed('jabber');
     // Some validation
     if (!$jabber) {
         $this->showForm(_('No Jabber ID.'));
         return;
     }
     $jabber = jabber_normalize_jid($jabber);
     if (!$jabber) {
         $this->showForm(_('Cannot normalize that Jabber ID'));
         return;
     }
     if (!jabber_valid_base_jid($jabber)) {
         $this->showForm(_('Not a valid Jabber ID'));
         return;
     } else {
         if ($user->jabber == $jabber) {
             $this->showForm(_('That is already your Jabber ID.'));
             return;
         } else {
             if ($this->jabberExists($jabber)) {
                 $this->showForm(_('Jabber ID already belongs to another user.'));
                 return;
             }
         }
     }
     $confirm = new Confirm_address();
     $confirm->address = $jabber;
     $confirm->address_type = 'jabber';
     $confirm->user_id = $user->id;
     $confirm->code = common_confirmation_code(64);
     $result = $confirm->insert();
     if ($result === false) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         $this->serverError(_('Couldn\'t insert confirmation code.'));
         return;
     }
     if (!common_config('queue', 'enabled')) {
         jabber_confirm_address($confirm->code, $user->nickname, $jabber);
     }
     $msg = sprintf(_('A confirmation code was sent ' . 'to the IM address you added. ' . 'You must approve %s for ' . 'sending messages to you.'), jabber_daemon_address());
     $this->showForm($msg, true);
 }
示例#2
0
 /**
  * Sends a confirmation to the address given
  *
  * Stores a confirmation record and sends out a
  * Jabber message with the confirmation info.
  *
  * @return void
  */
 function addAddress()
 {
     $user = common_current_user();
     $jabber = $this->trimmed('jabber');
     // Some validation
     if (!$jabber) {
         // TRANS: Message given saving IM address without having provided one.
         $this->showForm(_('No Jabber ID.'));
         return;
     }
     $jabber = jabber_normalize_jid($jabber);
     if (!$jabber) {
         // TRANS: Message given saving IM address that cannot be normalised.
         $this->showForm(_('Cannot normalize that Jabber ID'));
         return;
     }
     if (!jabber_valid_base_jid($jabber, common_config('email', 'domain_check'))) {
         // TRANS: Message given saving IM address that not valid.
         $this->showForm(_('Not a valid Jabber ID'));
         return;
     } else {
         if ($user->jabber == $jabber) {
             // TRANS: Message given saving IM address that is already set.
             $this->showForm(_('That is already your Jabber ID.'));
             return;
         } else {
             if ($this->jabberExists($jabber)) {
                 // TRANS: Message given saving IM address that is already set for another user.
                 $this->showForm(_('Jabber ID already belongs to another user.'));
                 return;
             }
         }
     }
     $confirm = new Confirm_address();
     $confirm->address = $jabber;
     $confirm->address_type = 'jabber';
     $confirm->user_id = $user->id;
     $confirm->code = common_confirmation_code(64);
     $confirm->sent = common_sql_now();
     $confirm->claimed = common_sql_now();
     $result = $confirm->insert();
     if ($result === false) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         // TRANS: Server error thrown on database error adding IM confirmation code.
         $this->serverError(_('Couldn\'t insert confirmation code.'));
         return;
     }
     jabber_confirm_address($confirm->code, $user->nickname, $jabber);
     // TRANS: Message given saving valid IM address that is to be confirmed.
     // TRANS: %s is the IM address set for the site.
     $msg = sprintf(_('A confirmation code was sent ' . 'to the IM address you added. ' . 'You must approve %s for ' . 'sending messages to you.'), jabber_daemon_address());
     $this->showForm($msg, true);
 }
 /**
  * @dataProvider normalizationCases
  *
  */
 public function testNormalize($jid, $expected)
 {
     $this->assertEquals($expected, jabber_normalize_jid($jid));
 }
示例#4
0
 function handle_presence(&$pl)
 {
     $from = jabber_normalize_jid($pl['from']);
     switch ($pl['type']) {
         case 'subscribe':
             # We let anyone subscribe
             $this->subscribed($from);
             $this->log(LOG_INFO, 'Accepted subscription from ' . $from);
             break;
         case 'subscribed':
         case 'unsubscribed':
         case 'unsubscribe':
             $this->log(LOG_INFO, 'Ignoring  "' . $pl['type'] . '" from ' . $from);
             break;
         default:
             if (!$pl['type']) {
                 $user = User::staticGet('jabber', $from);
                 if (!$user) {
                     $this->log(LOG_WARNING, 'Presence from unknown user ' . $from);
                     return;
                 }
                 if ($user->updatefrompresence) {
                     $this->log(LOG_INFO, 'Updating ' . $user->nickname . ' status from presence.');
                     $this->add_notice($user, $pl);
                 }
                 $user->free();
                 unset($user);
             }
             break;
     }
     unset($pl['xml']);
     $pl['xml'] = null;
     $pl = null;
     unset($pl);
 }