]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Initial user doesn't need as strict checking on email
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 16 Jan 2016 16:20:26 +0000 (17:20 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 16 Jan 2016 16:23:50 +0000 (17:23 +0100)
classes/User.php
lib/emailexception.php [new file with mode: 0644]
lib/installer.php
lib/mail.php

index c8b334d489ab76c553f7a27e6601c1cb63c397d3..c232b2b12f307c8c2ee2e0d60cc069a3746612f4 100644 (file)
@@ -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 (file)
index 0000000..417bfe1
--- /dev/null
@@ -0,0 +1,34 @@
+<?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
+{
+}
index 971e2562b010d6fb5eb1897309943f32d5cbc46b..650845f0f06712b16958fca6c865dd3eba3650fe 100644 (file)
@@ -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;
         }
index 2076476f875c54c6171eb05777a4072024f89a88..da22eb6715a1b2c333ae0cf60f6271f513e373f5 100644 (file)
@@ -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) {