2014-11-02 29 views
0

我收到了一个我想了解的错误:SQLSTATE [42S22]:列未找到:1054'where子句'中的未知列'username'(SQL:select * from users where ID电子邮件密码名admin created_at的updated_at 1 [email protected] $ 2Y $ 10 $ 1R/21A3C32nwkjtEgDFcyuMc2D4AtgeFnTh1ygLEcQl ...去:试图登录Laravel身份验证系统 - 表格不匹配

我的 '用户' 表时username = [email protected]限制1) 1 2014-11-01 21:04:33 2014-11-01 21:04:33 2 [email protected] $ 2y $ 10 $ Akb9BoLWrOcQT0KFee7vvujtrzkbeRQnUDcuCXepeAd ... hi 0 2014-11-02 16:15:47 2014年4月1日 - 11-02 16:15:47

我的意见(正确显示)形式

@extends('login_c') 

@section('loginform') 
<?= '<span style="color:red">' . 
Session::get('login_error') . '</span>' ?> 
{{ Form::open() }} 
{{ Form::label('email', 'Email address: ') }} 
{{ Form::text('email', Input::old('email')) }} 
<br> 
{{ Form::label('password', 'Password: ') }} 
{{ Form::password('password') }} 
<br> 
{{ Form::submit('Login!') }} 
{{ Form::close() }} 


@stop 

的问题是,我之前指定我的密码注册,我不明白为什么我要么得到“无法登录”或SQL注入错误。

oute::get('registration', function() 
{ 
return View::make('registration'); 
}); 

Route::post('registration', array('before' => 'csrf', 
function() 
{ 
    $rules = array(
    'email' => 'required|email|unique:users', 
    'password' => 'required|same:password_confirm', 
    'name' => 'required' 
    ); 

    $validation = Validator::make(Input::all(), $rules); 
    if ($validation->fails()) 
    { 
     return Redirect::to('registration')->withErrors 
     ($validation)->withInput(); 
    } 
    $user = new User; 
    $user->email = Input::get('email'); 
    $user->password = Hash::make(Input::get('password')); 
    $user->name = Input::get('name'); 
    $user->admin = Input::get('admin') ? 1 : 0; 
    if ($user->save()) 
    { 
     Auth::loginUsingId($user->id); 
     return Redirect::to('profile'); 
    } 
    return Redirect::to('registration')->withInput(); 
})); 

Route::get('profile', function() 
{ 
if (Auth::check()) 
{ 
return 'Welcome! You have been authorized!'; 
} 
else 
{ 
return 'Please <a href="login">Login</a>'; 
} 
}); 

Route::get('login', function() 
{ 
return View::make('login'); 
}); 

Route::post('login', function() 
{ 
$user = array(
'name' => Input::get('email'), 
'password' => Input::get('password') 
); 
if (Auth::attempt($user)) 
{ 
return Redirect::to('profile'); 
} 
return Redirect::to('login')->with('login_error', 
'Could not log in.'); 
}); 

Route::get('secured', array('before' => 'auth', function() 
{ 
return 'This is a secured page!'; 
})); 

我的登记表。(对不起,我没有张贴我的众目睽睽之下,因为它是不相关的,我敢肯定,误差在形式和/或的usermodel

{{ Form::open() }} 
{{ Form::label('email', 'Email address: ') }} 
{{ Form::text('email', Input::old('email')) }} 
<br> 
{{ Form::label('password', 'Password: ') }} 
{{ Form::password('password') }} 
<br> 
{{ Form::label('password_confirm', 
'Retype Password: ') }} 
{{ Form::password('password_confirm') }} 
<br> 
{{ Form::label('name', 'Name: ') }} 
{{ Form::text('name', Input::old('name')) }} 
<br> 
{{ Form::label('admin', 'Admin?: ') }} 
{{ Form::checkbox('admin','true', 
Input::old('admin')) }} 
<br> 
{{ Form::submit('Register!') }} 
{{ Form::close() }} 


@stop 

我应该如何改变我的用户模型?为什么它保存了错误的密码?

回答

1

试图改变

$user = array(
'name' => Input::get('email'), 
'password' => Input::get('password') 
); 

$user = array(
'email' => Input::get('email'), // You're using email to log in users, not name in your form 
'password' => Input::get('password') 
); 
+0

谢谢。一个问题:如果我打开数据库,为什么会显示错误的密码?这是一个安全功能吗? – Thankyou 2014-11-02 17:36:59

+0

@StephanieNess不客气。你是什​​么意思* ...如果我打开数据库显示错误的密码... *? – peterm 2014-11-03 00:37:45