Cannot create new users using UI


#1

For my development environment, I don’t want to setup a working email service — so during the “php bakery bake” process I answered no at that prompt. There was a warning message saying public registrations would then be impossible …

[WARNING] By not setting up any outgoing mail server, public account registration won’t work.

Okay, that’s fine — I will not have any users registering themselves.

However, what is happening is that even I cannot create new users logged in as the admin. Here is the message I get …

Fatal error attempting mail, contact your server administrator. If you are the admin, please check the UserFrosting log.

And the log shows this …

[2018-10-08 13:07:41] mail.DEBUG: Invalid address: [] []

NOTE: I have submitted a patch to work around this issue …


#2

Thanks! We also have another proposed patch here: https://github.com/userfrosting/UserFrosting/pull/764

Personally, I would like to implement an adapter pattern for the Mailer service, so that during development, mail can simply be sent to a file instead of an actual mail server. This would also let you debug the contents and styling of your mail during development, without actually needing to send the email.


#3

Hi @alexweissman, that would be nice. I also thought about installing MailHog (would also be nicer that what I did.)

This was just a quick way around for what I needed right now … edited the create function in admin sprinkle’s UserController.php file …

    $isEmailConfigured=!empty($config['mail']['host']);
    if(!$isEmailConfigured)
    {
        // Final message without sending an email.
        $ms->addMessageTranslated('success', 'User created WITHOUT welcome email!');
    } else {
        // Send welcome email with password set link
        $message = new TwigMailMessage($this->ci->view, 'mail/password-create.html.twig');

        $message->from($config['address_book.admin'])
                ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name))
                ->addParams([
                    'user' => $user,
                    'create_password_expiration' => $config['password_reset.timeouts.create'] / 3600 . ' hours',
                    'token' => $passwordRequest->getToken()
                ]);

        $this->ci->mailer->send($message);
        $ms->addMessageTranslated('success', 'USER.CREATED', $data);
    }

#4

@frankfont looks good - but you’d be better off copy-pasting UserController::create to a controller in your own Sprinkle, and then overriding the appropriate routes to point to your own controller method. That way, you can pull in updates to the admin Sprinkle without losing any of your changes.