vendredi 18 septembre 2015

Laravel 5 TokenMismatchException on login

I developed an application with laravel locally with homestead and now I try to get it running on a shared host. As soon as I hit the login button I get the exception: TokenMismatchException in VerifyCsrfToken.php line 53

I read that many people have problems with the TokenMismatchException but all of the proposed solutions didn't work for me. I deleted all files in the storage/framework/sessions folder (and the folder has 777 permissions). I deleted all cookies and since I use {!! Form:open !!} the hidden _token field exists (I also posted the source code).

My whole app expects the user to be logged in, so immediately after visiting the page I get redirected to the login form.

auth/login.blade.php

@extends('app')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Login</div>
                <div class="panel-body">

                    {!! Form::open(array('url' => '/auth/login', 'class' => 'form-horizontal')) !!}

                        <div class="form-group">
                            <label class="col-md-4 control-label">E-Mail Address</label>
                            <div class="col-md-6">
                                    {!! Form::email('email', null, ['class' => 'form-control']) !!}
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-4 control-label">Password</label>
                            <div class="col-md-6">
                                {!! Form::password('password', ['class' => 'form-control']) !!}
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                {!! Form::checkbox('remember', '1', false, ['id' => 'remember']) !!}&nbsp;
                                {!! Form::label('remember', 'Remember Me') !!}
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                {!! Form::submit("Login", ['class' => 'btn btn-block btn-primary']) !!}
                            </div>
                        </div>

                    {!! Form::close() !!}

                    @if (count($errors) > 0)
                        <div class="alert alert-danger">
                            <strong>Whoops!</strong> There were some problems with your input.<br><br>
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                </div>
            </div>
        </div>
    </div>
</div>
@endsection

This is how the source code looks like:

    <input name="_token" type="hidden" value="HoSZ4shS8b1avwrkJZzGiUQCWRZL0VPtj3mfvJmI">

    <div class="form-group">
        <label class="col-md-4 control-label">E-Mail Address</label>
        <div class="col-md-6">
            <input class="form-control" name="email" type="email">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4 control-label">Password</label>
        <div class="col-md-6">
            <input class="form-control" name="password" type="password" value="">
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <input id="remember" name="remember" type="checkbox" value="1">&nbsp;
            <label for="remember">Remember Me</label>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <input class="btn btn-block btn-primary" type="submit" value="Login">
        </div>
    </div>

</form>

Part of my routes.php

Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

I'm not sure which code is necessary to see to be able to help me with this, please let me know if I need to post some more.

Thanks to everyone who cares about my question.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire