mercredi 10 août 2016

Flash message not rendered when redirected through auth middleware

I'm successfully using flash messaging throughout my web application and do so using the Laracasts Flash package.

On my application users have the ability to change their email addresses, for which they are sent a link to confirm this.

When they click the link and are already logged in then this works fine and they are redirected to their profile successfully with a flash message to confirm this.

However when I click on the link, but am not logged in to the account, the change goes through successfully and then I am redirected to the login page as you cannot access the profile page without being logged in. This is intended, however my flash message isn't shown and doesn't appear to be included in the session data.

The function that handles the changing of the email address is included in my except array for the auth middleware on this controller but the profile page isn't.

As far as I can tell this should work... Any ideas?

public function emailconfirm($token)
    {

        $result = EmailChange::where('token', '=', $token)->get();

        if (!$result->isEmpty())
        {
            if ($result[0]->confirmed == 1)
            {
                flash()->error('You have already confirmed your email address using that token.');
                return redirect('/user');
            }

            if(count(User::where('email', $result[0]->new_email)->first()) > 0)
            {
                flash()->error('That email address has since been used to register an account, so it cannot be verified. Please contact us via the forums if you need help.');
                return redirect('/');
            }

            $user = User::find($result[0]->memberid);
            $user->email = $result[0]->new_email;
            $user->save();

            $result[0]->confirmed = 1;
            $result[0]->save();

            flash()->success('Email successfully updated.');

            return redirect('/user');
        }
    }

My login page does have the necessary code to show the flash message.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire