Initial user doesn't need as strict checking on email

This commit is contained in:
Mikael Nordfeldth 2016-01-16 17:20:26 +01:00
parent 67801a5566
commit bdc38a7204
4 changed files with 47 additions and 6 deletions

View File

@ -207,7 +207,7 @@ class User extends Managed_DataObject
* @return User object * @return User object
* @throws Exception on failure * @throws Exception on failure
*/ */
static function register(array $fields) { static function register(array $fields, $accept_email_fail=false) {
// MAGICALLY put fields into current scope // MAGICALLY put fields into current scope
@ -371,8 +371,15 @@ class User extends Managed_DataObject
$profile->query('COMMIT'); $profile->query('COMMIT');
if (!empty($email) && !$user->email) { if (!empty($email) && !empty($user->email)) {
try {
mail_confirm_address($user, $confirm->code, $profile->nickname, $email); 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 // Welcome message

34
lib/emailexception.php Normal file
View File

@ -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
{
}

View File

@ -524,7 +524,7 @@ abstract class Installer
$data['email'] = $this->adminEmail; $data['email'] = $this->adminEmail;
} }
try { try {
$user = User::register($data); $user = User::register($data, true); // true to skip email sending verification
} catch (Exception $e) { } catch (Exception $e) {
return false; return false;
} }

View File

@ -52,7 +52,7 @@ function mail_backend()
$backend = $mail->factory(common_config('mail', 'backend'), $backend = $mail->factory(common_config('mail', 'backend'),
common_config('mail', 'params') ?: array()); common_config('mail', 'params') ?: array());
if ($_PEAR->isError($backend)) { if ($_PEAR->isError($backend)) {
throw new ServerException($backend->getMessage()); throw new EmailException($backend->getMessage(), $backend->getCode());
} }
} }
return $backend; return $backend;
@ -82,7 +82,7 @@ function mail_send($recipients, $headers, $body)
assert($backend); // throws an error if it's bad assert($backend); // throws an error if it's bad
$sent = $backend->send($recipients, $headers, $body); $sent = $backend->send($recipients, $headers, $body);
if ($_PEAR->isError($sent)) { if ($_PEAR->isError($sent)) {
throw new ServerException($sent->getMessage()); throw new EmailException($sent->getMessage(), $sent->getCode());
} }
return true; return true;
} catch (PEAR_Exception $e) { } catch (PEAR_Exception $e) {