By default Laravel 5.5's password reset system works on email, but I need to add support for a mobile number (verify by OTP and generate a token and redirect to password reset page). I am doing all this part and I have created a mobile column on password_resets table.
But the problem is \Illuminate\Auth\Passwords\DatabaseTokenRepository
&& \Illuminate\Auth\Passwords\TokenRepositoryInterface
ON exist
method and it doesn't seem configurable.
public function exists(CanResetPasswordContract $user, $token)
{
$record = (array) $this->getTable()->where(
'email', $user->getEmailForPasswordReset()
)->first();
return $record &&
! $this->tokenExpired($record['created_at']) &&
$this->hasher->check($token, $record['token']);
}
I need to override that method. There's so much inheritance going on. What classes do I need to extend and how to override that method.
If you want to override behaviour of
\Illuminate\Auth\Passwords\DatabaseTokenRepository
methods, you will have to override every method that references "email" column. Create these files:/App/Auth/DatabaseTokenRepository.php
Now you will need to use this custom token repository instead of the default one. So you have to override another class.
/App/Auth/PasswordBrokerManager.php
Now you have created a custom broker to use your custom repository. You need a new service provider to make use of it.
/App/Providers/PasswordResetServiceProvider.php
Then just replace default password reset service provider with the custom one in your application config.