How To: Shield - Send Email to user on Admin Created User - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34) +--- Thread: How To: Shield - Send Email to user on Admin Created User (/showthread.php?tid=87720) |
How To: Shield - Send Email to user on Admin Created User - DeanE10 - 05-23-2023 Stack Response reposted here This will cover how to send an email to a newly registered user using an Admin panel outside of Shields default Self Registration. The idea here is to maintain Shields default file system incase there is an update. We don't want to lose our work if we perform an update and it overwrites one of the files we modified. An additional use case would be based on the need to turn of Self Registration IE: $allowRegistration = false; FIRST: Make sure you have completed the setup - Composer will be your best option **************** 1. [Installation Link] 2. [Setup Link] **************** Once you are all setup and verified Shield is working properly, you can add an Authentication Action to perform the email task. Additional information on Authentication Actions can be found [here]. This will allow you to configure more if needed and defines the two provided by Shield (EmailActivate, Email2FA). Ok, Let's get to work! app/Config/Events.php We need to add an event to send the new user an email PHP Code: .... app/Controllers/Users.php PHP Code: .... email template -> CodeIgniter\Shield\Views\Email\email_manual_activate_email This is a very slightly modified version of the Shield's default file (action_email_activate_email). Was thinking it might better to put in a Majic-Link... Maybe later... PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Make sure you add this line in app/Config/Auth.php PHP Code: public array $views = [ Now your new users will receive an email when you set them up, even if PHP Code: $allowRegistration = false; Once they login for the first time, it will also send them a new code. Verifying the code will send them to wherever you have the force_reset redirect set to. I set this forcing the user to their Profile with a SweetAlert (again, I use lots of Ajax) to let them know they need to change their password. Plus, this is a great opportunity for them to enter all of their personal information as well. PHP Code: public array $redirects = [ With the personal or extra data I mention above that you need to enter into the DB for the user, you can either expand the users table, or create a new table. More information on that [here with code] to assist. Hope this helps! If you see a mistake or if your way is better, post it below! - Dean RE: How To: Shield - Send Email to user on Admin Created User - yamin88 - 08-21-2023 CodeIgniter\Shield\Exceptions\RuntimeException Cannot send email for user: I use default setup, why still unable to actvate/send the email, I wonder why RE: How To: Shield - Send Email to user on Admin Created User - datamweb - 09-03-2023 (08-21-2023, 04:59 PM)yamin88 Wrote: CodeIgniter\Shield\Exceptions\RuntimeException Make sure you have done the email settings in file app/Config/Email.php. Please refer to the description below. https://codeigniter4.github.io/shield/install/#command-setup |