【问题标题】:How to change the inbuilt Laravel 5 authentication system?如何更改内置的 Laravel 5 身份验证系统?
【发布时间】:2015-04-28 18:02:00
【问题描述】:

我是第一次使用 Laravel 5。我之前和4一起工作过。 Laravel 附带了一个 AuthenticatesAndRegisterUsers.php 文件,该文件处理大部分内容并使注册和登录用户变得非常容易。

我想调整此文件以满足我自己的需要,例如不记录用户,而是向他们发送激活链接并检查用户是否在登录时激活。

登录后

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

        $credentials = $request->only('email', 'password');

        if ($this->auth->attempt($credentials, $request->has('remember')))
        {
            if(!$this->auth->user()->activated)
            {
                $this->auth->logout();
                return redirect($this->loginPath())
                        ->withErrors(['activated' => 'Your account is not activated yet. <br /> Please check your email for activation link.']);
            }

            return redirect()->intended($this->redirectPath());
        }

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

注册后

public function postRegister(Request $request)
    {
        $validator = $this->registrar->validator($request->all());

        if ($validator->fails())
        {
            $this->throwValidationException(
                $request, $validator
            );
        }

        $this->registrar->create($request->all());

        return redirect($this->loginPath())
            ->withErrors(['activated' => 'Activation link has been sent to your email address.']);
    }

这对我来说就像一个魅力,但后来我意识到我已经编辑了供应商文件以满足我的需要,因为这个文件位于供应商文件夹中。当然,它不会提交版本控制。

所以我的问题是如何使用 Laravel 5 身份验证系统,但在此过程中也适合我的需要。我可以以某种方式扩展这个类并覆盖这些方法,还是我必须完全编写自己的类?

【问题讨论】:

    标签: php authentication laravel-5


    【解决方案1】:

    您可以在AuthController(或任何使用该特征的控制器)中覆盖这些方法。只需复制这两个函数,就可以开始了。

    【讨论】:

      猜你喜欢
      • 2015-06-08
      • 2015-07-01
      • 2016-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多