Zizaco / confide

Confide is a authentication solution for Laravel 4
1.19k stars 259 forks source link

Serialization of 'Closure' is not allowed #522

Open ravigupta112 opened 9 years ago

ravigupta112 commented 9 years ago

When i submit the forgot password form i getting the "Serialization of 'Closure' is not allowed" Exceptio

after debugging i find the code from there error is reproduced

// File : confide/src/Confide/EloquentPasswordService.php

// Code: protected function sendEmail($user, $token) { $config = $this->app['config']; $lang = $this->app['translator'];

    $this->app['mailer']->queueOn(
        $config->get('confide::email_queue'),
        $config->get('confide::email_reset_password'),
        compact('user', 'token'),
        function ($message) use ($user, $token, $lang) {
            $message
                ->to($user->email, $user->username)
                ->subject($lang->get('confide::confide.email.password_reset.subject'));
        }
    );
} 
Remo commented 9 years ago

did you ever find a solution to this problem?

GrahamCampbell commented 9 years ago

did you ever find a solution to this problem?

Do $user->toArray() or something, but don't try to serialise the entire user object - that won't work.

GrahamCampbell commented 9 years ago

It doesn't work because you end up trying to serialise the entire laravel service container and all resolved objects, lol.

Remo commented 9 years ago

I'm just calling the password reset method.. will give you more details when I'm in front of a computer.

Remo commented 9 years ago

@GrahamCampbell I'm only calling Confide::forgotPassword(Input::get('email')). Using version 4.2.

Remo commented 9 years ago

I think this happens because $lang = $this->app['translator']; returns object(Polyglot\Services\Lang). It seems like polyglot can't be serialized that easily..

A workaround would be easy, I just replace the IoC with Lang::get to avoid polyglot and everything is fine, but that's not really what I want to do.

    protected function sendEmail($user, $token)
    {
        $config = $this->app['config'];

        $this->app['mailer']->queueOn(
            $config->get('confide::email_queue'),
            $config->get('confide::email_reset_password'),
            compact('user', 'token'),
            function ($message) use ($user, $token) {
                $message
                    ->to($user->email, $user->username)
                    ->subject(Lang::get('confide::confide.email.password_reset.subject'));
            }
        );
    }

Compare to: https://github.com/Zizaco/confide/blob/master/src/Confide/EloquentPasswordService.php#L169-L184