From bdc38a7204dc83e17b5a251a568447b8e23d533e Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 16 Jan 2016 17:20:26 +0100 Subject: [PATCH] Initial user doesn't need as strict checking on email --- classes/User.php | 13 ++++++++++--- lib/emailexception.php | 34 ++++++++++++++++++++++++++++++++++ lib/installer.php | 2 +- lib/mail.php | 4 ++-- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 lib/emailexception.php diff --git a/classes/User.php b/classes/User.php index c8b334d489..c232b2b12f 100644 --- a/classes/User.php +++ b/classes/User.php @@ -207,7 +207,7 @@ class User extends Managed_DataObject * @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 @@ -371,8 +371,15 @@ class User extends Managed_DataObject $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 diff --git a/lib/emailexception.php b/lib/emailexception.php new file mode 100644 index 0000000000..417bfe127b --- /dev/null +++ b/lib/emailexception.php @@ -0,0 +1,34 @@ +. + * + * @category Exception + * @package GNUsocial + * @author Mikael Nordfeldth + * @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 +{ +} diff --git a/lib/installer.php b/lib/installer.php index 971e2562b0..650845f0f0 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -524,7 +524,7 @@ abstract class Installer $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; } diff --git a/lib/mail.php b/lib/mail.php index 2076476f87..da22eb6715 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -52,7 +52,7 @@ function mail_backend() $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; @@ -82,7 +82,7 @@ function mail_send($recipients, $headers, $body) 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) { -- 2.39.5