从今天开始,我的登录控制器(使用 Sentry)不再工作了。我已经将它更改了 10203902 次,但它一直给我错误:“需要 [登录] 属性”。在过去的 2-3 周内,此控制器运行良好。
登录控制器
<?php namespace Digitus\Auth\Controllers;
use Illuminate\View\Environment as View;
use Cartalyst\Sentry\Sentry;
use Illuminate\Support\Facades\Input;
use Illuminate\Routing\Redirector as Redirect;
class LoginController extends \Digitus\Base\Controllers\BController{
public function __construct(Input $input, View $view, Sentry $sentry, Redirect $redirect){
$this->input = $input;
$this->view = $view;
$this->sentry = $sentry;
$this->user = $this->sentry->getUser();
$this->redirect = $redirect;
if($this->sentry->check()) {
$user = $this->sentry->getUser();
} else {
$user = null;
}
$this->view->share('loggedUser', $user);
}
protected $input;
protected $view;
protected $sentry;
protected $redirect;
public function index()
{
return $this->view->make('user.login');
}
public function login()
{
$user = $this->user->where('username', $this->input->get('email_or_username'))->orWhere('email', $this->input->get('email_or_username'))->first();
$credentials = array(
'email' => Input::get('email_or_username') ?: null,
'password' => $this->input->get('password'),
);
try {
$user = $this->sentry->authenticate($credentials, false);
if($this->sentry->check())
{
return $this->redirect->to('admin');
} else {
return $this->redirect->to('');
}
}
catch (\Exception $e)
{
return $this->redirect->to('login')->withErrors(array('login'=> $e->getMessage()));
}
}
}
看法
@extends('layouts.main')
@section('content')
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading">PLease Login</div>
<div class="panel-body">
{{ Form::open(array('url' => 'login')) }}
@if($errors->has('login'))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert">×</a>
{{ $errors->first('login', ':message') }}
</div>
@endif
<div class="form-group">
{{ Form::label('email_or_username', 'Email Address or Username') }}
{{ Form::email('email_or_username', '', array('class'=>'form-control','placeholder'=>'Please enter your Email Address or Username to login', 'autofocus')) }}
</div>
<div class="form-group">
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array('class'=>'form-control', 'placeholder'=>'Password')) }}
</div>
<div class="form-group">
{{ Form::submit('Login', array('class'=>'btn btn-success')) }}
{{ HTML::link('/', 'Cancel', array('class'=>'btn btn-danger')) }}
</div>
<hr>
<div class="form-group">
<h2>Don't have an account?</h2>
{{ HTML::link('register', 'Please register here', array('class'=>'btn btn-primary btn-xs'))}}
</div>
{{ Form::close() }}
</div>
</div>
</div>
@stop
我已经问过很多人的解决方案或修复等。他们都没有工作..
PS & FYI:我还发布了 Sentry 配置,并且 login_attribute 是电子邮件。任何帮助或输入都会很棒。提前致谢..