function run() { if (!$this->start()) { return false; } $this->log(LOG_INFO, 'checking for queued confirmations'); do { $confirm = $this->next_confirm(); if ($confirm) { $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address); $user = User::staticGet($confirm->user_id); if (!$user) { $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id); continue; } $success = jabber_confirm_address($confirm->code, $user->nickname, $confirm->address); if (!$success) { $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address); # Just let the claim age out; hopefully things work then continue; } else { $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address); # Mark confirmation sent; need a dupe so we don't have the WHERE clause $dupe = Confirm_address::staticGet('code', $confirm->code); if (!$dupe) { common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__); continue; } $orig = clone $dupe; $dupe->sent = $dupe->claimed; $result = $dupe->update($orig); if (!$result) { common_log_db_error($dupe, 'UPDATE', __FILE__); # Just let the claim age out; hopefully things work then continue; } $dupe->free(); unset($dupe); } $user->free(); unset($user); $confirm->free(); unset($confirm); $this->idle(0); } else { # $this->clear_old_confirm_claims(); $this->idle(10); } } while (true); if (!$this->finish()) { return false; } return true; }
/** * 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); }
/** * 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); }