php - Laravel 5.1 - 验证用户名、密码,如果确认 = 1

标签 php authentication laravel-5 laravel-5.1 laravel-authorization

为这看似简单的任务大费周章。我使用以下代码在我的 AuthController 中使用 username 而不是 email:

/**
 * Set the login system to use username instead of email address
 * @var string
 */
protected $username = 'username';

这在很长一段时间内都运行良好(当我不打算让用户激活他们的帐户时)。但是,现在我需要用户激活他们的帐户,我知道在他们可以看到他们的仪表板之前我需要对登录进行额外的检查。

我已将下面的 postLogin() 方法修改为我认为正确的方法:

public function postLogin(Request $request)
{
    $this->validate($request, [
        'username' => 'required', 'password' => 'required',
    ]);

    $credentials = $request->only('username', 'password');
    $credentials = array_add($credentials, 'confirmed', '1');

    if ($this->auth->attempt($credentials, $request->has('remember')))
    {
        return redirect()->intended($this->redirectPath());
    }

    return redirect($this->loginPath())
                ->withInput($request->only('username', 'remember'))
                ->withErrors([
                    'username' => $this->getFailedLoginMessage(),
                ]);
}

但我得到的只是以下错误:

未定义的属性:App\Http\Controllers\Auth\AuthController::$auth

我做错了什么?

安迪

最佳答案

我在那里看到的只是一个小故障。

if ($this->auth->attempt($credentials, $request->has('remember')))

应该是

if (Auth::attempt($credentials, $request->has('remember')))

关于php - Laravel 5.1 - 验证用户名、密码,如果确认 = 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35276784/

相关文章:

security - 通过另一个 REST API 进行 Spring Rest API 身份验证

php - 在laravel中获取没有扩展名的文件名?

php - 在编辑原始图像的同时裁剪图像的小版本

ruby-on-rails - Ruby on Rails - 电子邮件确认链接给出 nomethoderror

php - 无法在 Eloquent 多态关系中获取数据

php - 避免除以零错误 Laravel 框架

mysql - 当我试图从数据库中获取数据到文本字段时,显示错误

php - 将表添加到数据库需要重新加载站点,为什么?

php - 如何在 Symfony2 中使用 jquery/Ajax 从 PHP 文件中获取数组字段值?

PHP-CRUD-API - 身份验证的最佳方式