Using Laravel 5.2
I need to overwrite a couple of pieces of functionality / add some new stuff to the password reset process. I've know I can overwrite the functionality in Illuminate\Foundation\Auth\ResetsPasswords
using the Password Controller that comes out of the tin.
I also need to make changes in Illuminate\Contracts\Auth\PasswordBroker
. My goal is to have an invitation email for setting an initial password that uses the existing password reset functionality. The only problem is in the function sendResetLink
.
This function gets the password token and sends the email via the reset password email view. I still need the password reset functionality, but I can't have an invitation email with 'reset your password' verbiage.
How can I do this? I think I can duplicate and tweak the functionality on the reset classes to use an invite view for the email, but I can't figure out how to extend the broker class to make this work.
The most common usage of PasswordBroker is to send the password reset link to users' emails by chaining it with sendResetLink () method. In the background, it uses the provider specified by given broker in auth.php. What magical about it is that at the end you will end up with User model or other model extending Authenticable
So, all you need to do is run your database migrations: Laravel includes Auth\ForgotPasswordController and Auth\ResetPasswordController classes that contains the logic necessary to e-mail password reset links and reset user passwords. All of the routes needed to perform password resets may be generated using the make:auth Artisan command:
The most common usage of PasswordBroker is to send the password reset link to users' emails by chaining it with sendResetLink () method. In the background, it uses the provider specified by given broker in auth.php.
The better thing to do would be to tell Laravel to use PHPMailer instead of SwiftMailer whenever it needs to mail anything. This way, all the Laravel code stays the same.
I was struggling with the same thing. I added a setEmailView() method to my custom PasswordBroker and called that just before sending the resetlink in AuthController, but that broke the regular password reset function.
So, I scrapped all that and went for a much simpler approach. In AuthController.php, inject a variable into the password template.
view()->composer('auth.emails.password', function($view) {
$view->with(['register'=>true]);
});
Password::sendResetLink(['email'=>$data['email']], function($message) {
$message->subject('Registration Email');
});
Then, in the template auth/emails/password.blade.php
@if ( isset($register) )
Whatever you want to say in registration Email.
@else
Normal password reset Email here.
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With