【发布时间】:2014-12-29 08:48:50
【问题描述】:
我得到一个我想理解的错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where clause' (SQL: select * from users where username = hi@ hi.hi 限制 1) 尝试登录时
我的“用户”表: id 电子邮件密码名称 admin created_at updated_at 1 go@go.go $2y$10$1R/21A3C32nwkjtEgDFcyuMc2D4AtgeFnTh1ygLEcQl... 去 1 2014-11-01 21:04:33 2014-11-01 21:04:33 2 hi@hi.hi $2y$10$Akb9BoLWrOcQT0KFee7vvujtrzkbeRQnUDcuCXepeAd...嗨 0 2014-11-02 16:15:47 2014-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!';
}));
我的注册表单:(抱歉,我没有发布我的完整视图,因为它不相关,我确定错误出在表单和/或用户模型中。
{{ 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
我应该如何更改我的用户模型?为什么会保存错误的密码?
【问题讨论】: