我第一次使用Laravel 5。我之前和4人一起工作过。 Laravel附带了AuthenticatesAndRegisterUsers.php文件,该文件可以处理大部分内容,并且可以非常轻松地注册和登录用户。
我想调整此文件以满足我自己的需要,例如不记录用户,而是发送激活链接并检查用户是否在登录时激活。
postLogin
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(),
]);
}
的postRegister
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身份验证系统,但在此过程中也适合我的需求。我可以以某种方式扩展这个类并覆盖这些方法,还是我必须完全编写自己的类?
答案 0 :(得分:1)
您可以在AuthController
(或任何使用该特征的控制器)中覆盖这些方法。只需复制这两个功能就可以了。