hi im trying to make a good user auth form but i ve have had some problems , so first i tried this :
Route::get('login', function()
{
/* Get the login form data using the 'Input' class */
$userdata = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
/* Try to authenticate the credentials */
if(Auth::attempt($userdata))
{
// we are now logged in, go to admin
return Redirect::to('home');
}
else
{
return Redirect::to('login');
}
});
and this is the form blade page :
{{ Form::open(array('url' => 'login', 'class' => 'form-horizontal')) }}
<div class="control-group">
<label class="control-label" for="username"></label>
<div class="controls">
<input id="username" name="username" type="text" placeholder="" class="input-xlarge" required="">
</div>
</div>
<!-- Password input-->
<div class="control-group">
<label class="control-label" for="password"></label>
<div class="controls">
<input id="password" name="password" type="password" placeholder="" class="input-xlarge" required="">
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button id="submit" name="submit" class="btn btn-inverse"></button>
</div>
</div>
</fieldset>
and it gave me the redirect loop error
and then i tried this :
Route::get('login', function()
{
/* Get the login form data using the 'Input' class */
$user = new User;
$log = array(
$user -> username = Input::get('username'),
$user -> password = Input::get('password')
);
/* Try to authenticate the credentials */
if(Auth::attempt($log))
{
// we are now logged in, go to admin
return Redirect::to('home');
}
else
{
return Redirect::to('login');
}
});
and it gives me :
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `users` where `0` is null and `1` is null limit 1)
does anyone knows whats the problem? first code should have worked perfectly but why redirect error?