【发布时间】:2014-06-15 14:44:02
【问题描述】:
我正在尝试进行基本身份验证,当我尝试对用户进行身份验证时,Auth :: attempt 方法返回 false
刀片
{{ Form::open(array('url' => 'usuario')) }}
<input type="text" class="text" id="email" name="email" placeholder="Correo" {{(Input::old('email')) ? 'value ="'. Input::old('email').'"' : '' }}>
<p>{{ $errors->first('email') }}</p>
<input type="text" class="text" id="password" name="password" placeholder="Contraseña" >
<p>{{ $errors->first('password') }}</p>
{{ Form::submit('Ingresar', array('class' => 'bg1')) }}
{{ Form::close() }}
控制器
class UsuarioController extends BaseController{
public function doLogin(){
$rules = array(
'email' => 'required|email',
'password' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()){
return Redirect::to('usuario')->withErrors($validator)->withInput(Input::except('password'));
}else{
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if(Auth::attempt($userdata)){
return View::make('hello');
}else{
return Redirect::to('usuario');
}
}
}
}
授权
'driver' => 'database',
'model' => 'Usuario',
'table' => 'Usuario',
型号
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class Usuario extends Eloquent implements UserInterface, RemindableInterface{
protected $table = 'Usuario';
protected $primaryKey = 'idUsuario';
protected $hidden = array('Contrasena');
protected $fillable = array(
'Nombre',
'Apellido',
'Tipo',
'password',
'email',
'Fono',
'Foto'
);
}
代码总是返回false并重定向我登录,数据库时使用不正确的数据
【问题讨论】:
标签: php authentication laravel laravel-4