登录失败和管理员认证laravel 4

时间:2014-11-28 01:57:09

标签: laravel login routes views

我的问题是,如果我输入网址http://localhost/loginhttp://localhost/admin,则返回无限循环浏览器。但是我创造了收入顺利的小组。

档案routes.php

#Crea la primera para hacer login
Route::get('/', function()
{
    return View::make('login');
});
 #Permite desloguear al usuario
Route::get('/logout', function()
{
    Auth::logout();
    #Al desloguear saca al usuario al index
    return Redirect::to('/');
});
#Enruta hacia el controlador para hacer el login 
Route::controller('check', 'Login');

#No permite el ingreso a panel sin antes estar auntentificado
Route::get('panel', array('before' => 'auth', function() {
   return View::make('dashboard.index');
}));

控制器中的文件Login.php

如果由管理面板替换,则进入登录和重定向面板。

<?php

class Login extends BaseController {

    public function postUser()
    {
        // get POST data
        $userdata = array(
            'username' => Input::get('username'),
            'password' => Input::get('password')
        );

        if(Auth::attempt($userdata))
        {
            // we are now logged in, go to admin
               return Redirect::to('panel');
        }
        else
        {

            return Redirect::to('/')->with('login_errors',true);
        }
    }
}

Filters.php

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('login');
        }
    }
});
Route::filter('auth.basic', function()
{
    return Auth::basic();
});

0 个答案:

没有答案