我是Laravel的新手并且一直关注有关身份验证的教程,但有些东西不起作用。 Auth ::尝试似乎正常。当它失败时,我被重定向回登录有错误,当它成功时,我被重定向到我的博客索引。可悲的是,在那之后我无法访问任何受保护的页面!我只是被重定向到我的登录页面。它让我发疯了!
我在博客索引视图中转储了一些变量,这些变量在Auth :: attempt成功查看正在进行的操作时呈现:
@section('content')
<h1>This is a blog!!</h1>
<?php
echo var_dump(Session::all());
echo var_dump(Auth::check());
foreach($posts as $post) { ?>
<div class="post">
<?php
echo "<h3><a href=\"/blog/$post->slug\">{$post->title}</a></h3>";
echo "{$post->content}";
?>
</div>
<?php } ?>
@stop
当我var_dump Session :: all()时,我得到了这个数组:
array(4) { ["_token"]=> string(40) "0hqRso6my0VpvQVtrXlLDeKioglu4xNXl5pbpNGM" ["flash"]=> array(2) { ["old"]=> array(0) { } ["new"]=> array(0) { } } ["url"]=> array(1) { ["intended"]=> string(49) "http://temporal-storm-743.appspot.com/blog/create" } ["login_82e5d2c56bdd0811318f0cf078b78bfc"]=> NULL }
当我转换为Auth :: check时,我得到false:bool(false)
我会在login_ur4iafo9之后假设NULL为什么意味着会话没有成功登录用户?
我还没有更改我在过滤器中使用默认情况下受保护网页的身份验证过滤器。
我已经检查了我的session.php文件:
'driver' => 'memcached',
'lifetime' => 120,
'expire_on_close' => false,
和我的auth.php
'driver' => 'eloquent',
'model' => 'User',
和我的模特......
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
public $timestamps = false;
protected $table = 'WebUser';
protected $primaryKey = 'WebUserId';
protected $hidden = array('password', 'remember_token');
}
当然还有我的登录控制器方法:
public function doLogin()
{
$rules = array(
'email'=>'required|email',
'password'=>'required|min:8'
);
$validator = Validator::make(Input::all(), $rules);
if( $validator->fails() )
return Redirect::back()->withInput(Input::except('password'))->withErrors($validator);
$userdata = array(
'email'=>Input::get('email'),
'password'=>Input::get('password'),
);
if ( !Auth::attempt($userdata, true) )
return Redirect::back()->withErrors(['email'=>'Login failed.']);
return Redirect::to('blog');
}
我不知道你们是怎么回事。
编辑:我知道现在发生了什么,你们。
度假结束后我回到了这个问题,开始在认证文件和论坛中探讨并试用了一些不同的auth方法。我认证工作正常!
我仍然不能100%确定原因,但Eloquent驱动程序似乎无法在Google App Engine上运行。从Eloquent更改为数据库身份验证后,更新我的数据库以便将所有主键设置为id并添加remember_token VARCHAR(100) NULL
作为字段,事情似乎正在进行身份验证。
也许有更多Laravel经验并且更了解不同提供商和身份验证工作如何帮助我理解为什么只有数据库身份验证才能在Google应用引擎上运行?
答案 0 :(得分:2)
我遇到了同样的问题,并在数小时内搜索了一个解决方案。
然后我改变了:
if(Auth::check()) return Redirect::to("/admin");
要:
if( ! Auth::guest()) return Redirect::to("/admin");
这对我有用.. :)
答案 1 :(得分:1)
我认为Laravel有一个错误。如果你使用Auth ::尝试验证你的凭证然后返回true并且&#39;销毁会话&#39;。所以我们重定向我们的url并使用Auth :: check()使其返回false。因为会话被破坏而你丢失了要检查的数据。