Magic link
Login without Password
To allow your customers to log in without a password by providing their email, you can use the kart-magic-link
-auth method provided by the Kart plugin. You will need to enable it in the config.
You will also need to configure Kirby to send emails.
<?php
return [
'auth' => [
'methods' => [
'password', // for you to log in panel
'kart-magic-link', // for the frontend
],
],
// other options
// TIP: do not forget to configure email settings
];
Custom Login Form
Instead of using Kirby's login form intended for Panel users, you should consider creating your own. The Kart plugin provides both the endpoints to start the authentication (send the email) and log in after clicking on the magic link.
<?php if (get('status') == 'sent') { ?>
<p><i>Login link was sent. Check your inbox.</i></p>
<?php } else { ?>
<form action="<?= kart()->urls()->magiclink() ?>" method="POST">
<label>
<input type="email" name="email" required
placeholder="<?= t('email') ?>" autocomplete="email"
value="<?= urldecode(get('email', '')) ?>">
</label>
<?php // TODO: You should add an CAPTCHA here, like...?>
<?php // snippet('kart/turnstile-form') // or ?>
<?php snippet('kart/captcha') ?>
<input type="hidden" name="redirect" value="<?= url('kart/login') ?>?status=sent">
<input type="hidden" name="success_url" value="<?= url('kart') ?>?msg=Welcome%20back">
<button type="submit"><?= t('login') ?> <?= t('link') ?></button>
</form>
<?php } ?>
Signup with magic link
Instead of using the login form with email and password, sending the customer an email with a magic link to log in without a password is possible. The exact process can also be used for the initial signup.
You can also provide a success_url
to which the new customers will be redirected after logging in via the magic link.
<?php if (get('status') == 'sent') { ?>
<p>Signup link was sent. Check your inbox.</p>
<?php } else { ?>
<form action="<?= kart()->urls()->signup_magic() ?>" method="POST">
<label>
<input type="email" name="email" required
placeholder="<?= t('email') ?>" autocomplete="email"
value="<?= urldecode(get('email', '')) ?>">
</label>
<label>
<input type="text" name="name" required
placeholder="<?= t('name') ?>" autocomplete="name"
value="<?= get('name') ?>">
</label>
<?php // TODO: You should add a CAPTCHA here, like...?>
<?php // snippet('kart/turnstile-form') // or ?>
<?php snippet('kart/captcha') ?>
<input type="hidden" name="redirect" value="<?= url('kart/signup') ?>?status=sent">
<input type="hidden" name="success_url" value="<?= url('kart') ?>?msg=Welcome">
<button type="submit">Sign up with magic link</button>
</form>
<?php }
Sending a login link programmatically
$user->sendMagicLink();