ARCANEDEV / Localization

:globe_with_meridians: Localization package for Laravel
MIT License
187 stars 37 forks source link

Auth Login POST (with wrong credentials) redirects to home? #61

Closed thusfar7 closed 8 years ago

thusfar7 commented 8 years ago

I localized all Auth routes.

When I go to Login and enter wrong credentials and submit it, I get redirected to home route? Any ideas or suggestion to why this might be happening?

$router->group([
    'prefix'     => Localization::setLocale(),
    'middleware' => [
        'web',
        'localization-session-redirect',
        'localization-redirect',
    ],
], function($router) {
    $router->group([
            'as'        => 'auth::',
            'namespace' => 'Auth',
        ], 
        function ($router) {
            // Authentication Routes...
            $router->group(['prefix' => 'login', 'as' => 'login.'], function ($router) {
                // auth::login.get
                $router->get('/',  ['as' => 'get',  'uses' => 'LoginController@showLoginForm']);
                // auth::login.post
                $router->post('/', ['as' => 'post', 'uses' => 'LoginController@login']);
            });

            // auth::logout
            $router->get('logout', ['as' => 'logout', 'uses' => 'LoginController@logout']);

            // Registration Routes...
            $router->group(['prefix' => 'register', 'as' => 'register.'], function ($router) {
                // auth::register.get
                $router->get('/',  ['as' => 'get',  'uses' => 'RegisterController@showRegistrationForm']);
                // auth::register.post
                $router->post('/', ['as' => 'post', 'uses' => 'RegisterController@register']);
            });
        }
    );
});
arcanedev-maroc commented 8 years ago

Can you check these issues first : #39 & #34

Check also this: https://github.com/ARCANEDEV/Localization/issues/58#issuecomment-244463420

thusfar7 commented 8 years ago

Okay so. As you can see my routes are properly defined.

Moving POST routes outside Localization group doesnt help.

Basically what happens is that "Login POST" redirects me to "home" route and from there to localized home route.

arcanedev-maroc commented 8 years ago

OK, can you tell me the Laravel version you're using ?

How did you register this routes ? with a RouteServiceProvider like this example ?

This is the proper way to register localized route:

$router->localizedGroup(function($router) {
    $router->group([
            'as'        => 'auth::',
            'namespace' => 'Auth',
        ], 
        function ($router) {
            // Authentication Routes...
            $router->group(['prefix' => 'login', 'as' => 'login.'], function ($router) {
                // auth::login.get
                $router->get('/',  ['as' => 'get',  'uses' => 'LoginController@showLoginForm']);
                // auth::login.post
                $router->post('/', ['as' => 'post', 'uses' => 'LoginController@login']);
            });

            // auth::logout
            $router->get('logout', ['as' => 'logout', 'uses' => 'LoginController@logout']);

            // Registration Routes...
            $router->group(['prefix' => 'register', 'as' => 'register.'], function ($router) {
                // auth::register.get
                $router->get('/',  ['as' => 'get',  'uses' => 'RegisterController@showRegistrationForm']);
                // auth::register.post
                $router->post('/', ['as' => 'post', 'uses' => 'RegisterController@register']);
            });
        }
    );
});

Make sure you're using route names in your form's action to avoid redirections while posting a form, like this:

<form action="{{ route('auth::login.post') }}" method="POST" class="form-horizontal" role="form">

Just follow this https://github.com/ARCANEDEV/Localization/issues/58#issuecomment-244463420 (Tested with Laravel 5.2) and you're going to be fine.

thusfar7 commented 8 years ago

I use 5.2. My auth routes look the same as in #58 as well as login view. Still it doesnt work.

arcanedev-maroc commented 8 years ago

So you're using this:

$router->localizedGroup(function($router) {
    //...
});

instead of this:

$router->group([
    'prefix'     => Localization::setLocale(),
    'middleware' => [
        'web',
        'localization-session-redirect',
        'localization-redirect',
    ],
], function($router) {
    //...
});

Did you tried to debug your LoginController and especially the login method (see here) ?

Did you changed the base code of \Illuminate\Foundation\Auth\AuthenticatesUsers Trait ?

Try to check each line like validateLogin(), getCredentials(), sendFailedLoginResponse() etc...

I've tested the localization package (on September) with a fresh Laravel 5.2 installation and it works without a problem.