Search code examples
phpfuelphpuser-registration

fuelphp confirm user registration in email using simple Auth Driver functionality


Im currently creating signup form in fuelphp how can I implement sending a user a verification link upon user signup? you can also suggest from other framework like laravel I only need the flow on implementing this. Thanks in advance ^_^


Solution

  • The general approach is that after registration you generate a confirmation token and you store it somewhere. It is also common that you set an is confirmed flag to false. In case of Simple Auth you might want to add some fields to the user table. Make sure to include them in the selected fields.

    You will also need a controller action which accepts the token. I would also put the username/email into the URL so that simply hitting the confirmation URL with random characters won't work. Find it by username/email and token and validate it, activate the user. Make sure that after validation you clear the token. You don't need it and you want to prevent double verification with the same token (in case you set the user to an unconfirmed state for some reason).

    A hook in the login action is needed as well: you need to check whether the account is validated or not. Do not authenticate at first, just validate the user. If it is valid, check if it is confirmed or not. If not, fail with error, if it is then continue with the login process.

    When the registration is complete, you send an email to the given email address with a URL to the confirmation page (generated URL containing username/email and confirmation token). (Username/email can be obfuscated/encrypted if it is reversible)