Ejemplo n.º 1
0
 /**
  * @dataProvider validationCases
  *
  */
 public function testValidate($jid, $validFull, $validBase)
 {
     $this->assertEquals($validFull, jabber_valid_full_jid($jid), "validating as full or base JID");
     $this->assertEquals($validBase, jabber_valid_base_jid($jid), "validating as base JID only");
 }
Ejemplo n.º 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) {
         $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);
 }
Ejemplo n.º 3
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);
 }