* @return User object
* @throws Exception on failure
*/
- static function register(array $fields) {
+ static function register(array $fields, $accept_email_fail=false) {
// MAGICALLY put fields into current scope
$profile->query('COMMIT');
- if (!empty($email) && !$user->email) {
- mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+ if (!empty($email) && !empty($user->email)) {
+ try {
+ mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+ } catch (EmailException $e) {
+ common_log(LOG_ERR, "Could not send user registration email for user id=={$user->id}: {$e->getMessage()}");
+ if (!$accept_email_fail) {
+ throw $e;
+ }
+ }
}
// Welcome message
--- /dev/null
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Class for an exception when there is something wrong with sending email
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Exception
+ * @package GNUsocial
+ * @author Mikael Nordfeldth <mmn@hethane.se>
+ * @copyright 2016 Free Software Foundation, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
+ * @link http://www.gnu.org/software/social/
+ */
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class EmailException extends Exception
+{
+}
$data['email'] = $this->adminEmail;
}
try {
- $user = User::register($data);
+ $user = User::register($data, true); // true to skip email sending verification
} catch (Exception $e) {
return false;
}
$backend = $mail->factory(common_config('mail', 'backend'),
common_config('mail', 'params') ?: array());
if ($_PEAR->isError($backend)) {
- throw new ServerException($backend->getMessage());
+ throw new EmailException($backend->getMessage(), $backend->getCode());
}
}
return $backend;
assert($backend); // throws an error if it's bad
$sent = $backend->send($recipients, $headers, $body);
if ($_PEAR->isError($sent)) {
- throw new ServerException($sent->getMessage());
+ throw new EmailException($sent->getMessage(), $sent->getCode());
}
return true;
} catch (PEAR_Exception $e) {