0

这是我的 postLogin 方法:

$userdata = array(
        'email'     => Input::get('email'),
        'password'  => Input::get('password'),
        'enabled'   => 1
    );

    if (Auth::attempt($userdata))
    {
        return Redirect::intended('/');
    }

    return Redirect::route('login')
        ->withInput(Input::except('password'))
        ->withErrors(array('password' => 'Password invalid'));

我在我的模型中使用 Ardent。由于我没有使用 Ardent->save(),如何验证登录表单并获取错误消息?

4

1 回答 1

0

像这样使用,

$input = Input::all();
$rules = array('email' => 'required|email', 'password' => 'required');

$validator = Validator::make($input, $rules);

if($validator->fails()) {
    return Redirect::to('login')->withInput()->withErrors($validator);
} else {

    $userdata = array(
            'email'     => Input::get('email'),
            'password'  => Input::get('password'),
            'enabled'   => 1
    );

    if (Auth::attempt($userdata)) {
        $remember = Input::get('remember');
        if(!empty($remember)) {
            Auth::login(Auth::user(), true);
        }
        return Redirect::intended('/');
    } else {
        return Redirect::to('login')
        ->withInput(Input::except('password'))
        ->withErrors(array('password' => 'Password invalid'));
    }

}
于 2013-10-04T03:23:27.890 回答