Support the ongoing development of Laravel.io →
Authentication Architecture
Last updated 2 years ago.
0

Try changing

Route::any('/user/login', array('as' => 'login', 'uses' => 'UserController@login'));    

to

Route::get('user/login', 'UserController@getLogin');
Route::post('user/login', 'UserController@postLogin');
Last updated 2 years ago.
0

Hey kreitje,

Even by changing it to:

Route::get('/user/login', array('as' => 'getlogin', 'uses' => 'UserController@login'));
Route::post('/user/login', array('as' => 'postlogin', 'uses' => 'UserController@login'));

it doesnt work. I still get a redirect loop.

Last updated 2 years ago.
0

Well, what your filter do is:

  • If it's ajax, block.
  • If it isn't redirect to login.

However, when you redirect, the second request is executed in a new instance of the framework, so the filter get re-executed. (you get where there is a loop in your logic?)

What you want to do is probably just block ajax request, but allow normal request to execute normaly. Your filter must be something like:

if (Auth::guest())
{
    if (Request::ajax())
    {
        return Response::make('Unauthorized', 401);
    }
}

Does it solve your problem?

Last updated 2 years ago.
0

Hey Atrakeur,

Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):

$this->beforeFilter('auth', array('except' => array('getLogin', 'postLogin')));

Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.

Example: UserController@index instead of UserController@getIndex.

As it does seem to show me the dashboard afterwards when using the second example.

Last updated 2 years ago.
0

goowikns said:

Hey Atrakeur,

Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):

So this isn't the problem. Maybe you can post a little more code to us so we can help better?

goowikns said:

Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.

Example: UserController@index instead of UserController@getIndex.

Well, you don't have to include the verb, But you have to set it to the exact name of the method. So if your method is getIndex, just write getIndex and not just index.

Where are you calling your $this->beforeFilter? What is $this in this context?

If you code is public, please post the github link so we can look at it?

Last updated 2 years ago.
0

Not sure what happened, works now, but it was partially due to the fact my routes weren't correctly written. I'm definetly going to start from scratch as I messed up so many things and generated way to many files at once without actually paying attention.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

goowikns goowikns Joined 18 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.