我遇到了問題,我的身份驗證不斷收到else語句,同時我在登錄表單中輸入了正確的電子郵件和密碼。隨着else語句我的意思是我SessionController的最後一行Laravel身份驗證失敗
else
{
return Redirect::to('login')
}
這裏是我的routes.php文件
// ~ Root
Route::get('/', array('as' => 'root', 'uses' => '[email protected]'));
// ~ Session ~ Login ~ Logout
Route::get('login', array('as' => 'newSession', 'uses' => '[email protected]'));
Route::post('login', array('as' => 'setSession', 'uses' => '[email protected]'));
Route::get('logout', array('as' => 'destroySession', 'uses' => '[email protected]'));
這裏是我的SessionController
<?php
class SessionController extends BaseController {
public function newSession() {
$this->layout->content = View::make('login');
}
public function setSession() {
$rules = array(
'email' => 'required|email',
'password' => 'required|alphaNum|min:3'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
// create our user data for the authentication
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata)) {
return Redirect::to('asd');
} else {
return Redirect::to('login')
->withErrors($validator)
->withInput(Input::except('password'));
// validation not successful, send back to form
// return Redirect::to('login')->withErrors($validator);
}
}
}
public function destroySession() {
Auth::logout();
return Redirect::to('login')->with('message', 'You are logged out');
}
}
這是我的形式
{{ Form::open(array('action' => '[email protected]', 'method' => 'POST', 'class' => 'form-horizontal navbar-form navbar-right')) }}
<div id="navbar" class="navbar-collapse collapse">
<div class="form-group">
<p>
{{ $errors->first('email') }}
{{ $errors->first('password') }}
</p>
<p>
{{ Form::label('email', 'Email Address', array('class' => 'navLogTxt')) }}
{{ Form::text('email', Input::old('email'), array('class' => 'form-control')) }}
{{ Form::label('password', 'Passwort', array('class' => 'navLogTxt')) }}
{{ Form::password('password', array('class' => 'form-control')) }}
{{ Form::submit('Anmelden!', array('class' => 'btn btn-success')) }}
</p>
</div>
</div>
{{ Form::close() }}
,最後,這是我的播種機
<?php
class UserTableSeeder extends Seeder {
public function run() {
DB::table('users')->delete();
User::create(array(
'email' => '[email protected]',
'password' => Hash::make('awesome')
));
User::create(array(
'email' => '[email protected]',
'password' => 'test'
));
}
}
密碼是在數據庫中加密還是以純文本形式存儲? – Bogdan
看看[這個答案](http://stackoverflow.com/a/15673247/351330),看看是否可以解決你的問題。 – Bogdan
密碼以明文形式存儲 – utdev