User Set Password after registering User in the panel

Hello all, I'm building a user resource that enables Admins to register users manually. When an action is toggled to enable the login, the action triggers the Email Verification process:
app()->bind(
\Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
\Filament\Listeners\Auth\SendEmailVerificationNotification::class,
);
// Trigger the email verification process
event(new Registered($this->record));
app()->bind(
\Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
\Filament\Listeners\Auth\SendEmailVerificationNotification::class,
);
// Trigger the email verification process
event(new Registered($this->record));
Now what I would like to achieve is to enable the user to set a password when he clicks the verify email. What would be your approach? I don't think fillament has anything under the hood ready for this after looking at the docs, but I may be wrong! Thank you!
10 Replies
awcodes
awcodes15mo ago
Could you redirect them to the reset password auth page instead of logging them in immediately on verification?
Diogo Pinto
Diogo PintoOP15mo ago
@awcodes you mean the set password after clicking the email? Or just the standard forgotten password page? Because the standard pages forces the user to go back to the email client
awcodes
awcodes15mo ago
They click the verify link, in that controller you can mark them as verified then redirect them to the forgotten password route. You just have to not log them in when verifying them. But you should be able to pass their email to the forgotten password route so it knows whose making the request. Guess they’d have do another email then though. But it’s certainly possible to do what your after.
Diogo Pinto
Diogo PintoOP15mo ago
I’ll take a look at the forgotten password logic to see if I can make anything happen. Will return with feedback soon.
awcodes
awcodes15mo ago
Even if you don’t use it specifically you should still be able to setup a ‘set password’ route and accomplish the same thing.
Diogo Pinto
Diogo PintoOP15mo ago
Yes, with a custom page probably, but I’m looking at how the token is generated/retrieved so I can rely on that logic. Thanks for your input! @awcodes and I've done it! Followed your logic... Here's how... On the form action generate a new token, and pass it to a notification, along with the password reset URL.
$token = app(\Illuminate\Auth\Passwords\PasswordBroker::class)->createToken($this->record);
$notification = new WelcomeEmail($token, Filament::getResetPasswordUrl($token, $this->record));
$this->record->notify($notification);
$token = app(\Illuminate\Auth\Passwords\PasswordBroker::class)->createToken($this->record);
$notification = new WelcomeEmail($token, Filament::getResetPasswordUrl($token, $this->record));
$this->record->notify($notification);
Edit the notification, so it isn't the standard one:
return (new MailMessage)
->subject(__('Set your password'))
->line(__('You are receiving this email because we activated your account on our app.'))
->action(__('Set Your Password'), $url)
->line(__('This link will expire in :count minutes. If it expires, you can always click "Forgotten your Password?" on our Login Page', ['count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')]));
return (new MailMessage)
->subject(__('Set your password'))
->line(__('You are receiving this email because we activated your account on our app.'))
->action(__('Set Your Password'), $url)
->line(__('This link will expire in :count minutes. If it expires, you can always click "Forgotten your Password?" on our Login Page', ['count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')]));
` Now the user gets an email to set his own password!
awcodes
awcodes15mo ago
Awesome, glad you got it working.
Arnaud
Arnaud13mo ago
Thank you, I've added a parameter to the url, &activation=true, by passing a new page to the AdminPanelProvider, passwordReset method, I can update the text if it's an activation or a regular reset password 🙂
xfly
xfly11mo ago
how did you made this?
Arnaud
Arnaud11mo ago
Hello, finally it wasn't working as expected .. so I ended it up by overwrite the auth pages
Want results from more Discord servers?
Add your server