I have setup a front end registration using the cookbook guide with the password
and code
auth methods.
However the email with the code in it to login with never arrives. Locally i can trap it using Mailhog and see the code and login that way, but on the test server and using Mailjet for SMPT (verified the API connection works via https://smtpdebug.com/).
No matter what i try, the email with the login code never arrives, i cant see any errors at all.
Here is my entire controller..
<?php
use Kirby\Cms\Auth\Status;
use Kirby\Exception\PermissionException;
use Kirby\Toolkit\V;
return function ($page, $pages, $kirby, $site) {
// SEO
$seo = $kirby->controller('seo', compact('page', 'site', 'kirby'));
// Override Meta Title
$metatitle = $page->title() . ' | ' . $site->title();
$sm = $page->shareimage()->toFile();
$metaimage = $sm ? $sm->crop(1200, 630)->url() : url('assets/images/social.webp');
// Login
// send already logged-in user somewhere else
$error = null;
// get authentication status
$status = $kirby->auth()->status();
// user is already logged in, send them elsewhere
if ($status->status() === 'active') {
go('home');
}
// form is submitted
if (get('login') && $kirby->request()->is('POST') ) {
// check CSRF token
if (csrf(get('csrf')) === true) {
// if we get an email address, we send an authentication challenge
if (get('email')) {
$email = get('email');
if (V::email($email)) {
try {
$status = $kirby->auth()->createChallenge($email, false, 'login');
} catch (PermissionException $e) {
$error = $e->getMessage();
}
} else {
$error = 'Please provide a valid email address';
}
// if we get a code, we validate the code
} elseif (get('code')) {
$code = get('code');
try {
// if successful, the user will be logged in
// `verifyChallenge()` either returns a user or throws an exception
$user = $kirby->auth()->verifyChallenge($code);
// if the user is logged-in, redirect them
if ($user) {
go('hone');
}
} catch (Exception $e) {
$error = $e->getMessage();
// set new status object with inactive status
$status = new Status([
'kirby' => $kirby,
'status' => 'inactive'
]);
}
}
} else {
$error = 'Invalid CSRF token';
}
}
$loginform = [
'email' => $email ?? '',
'error' => $error,
'status' => $status->status(),
];
// Pass on data...
$pagedata = compact('metatitle', 'metaimage');
return array_merge($seo, $pagedata, $loginform);
};
``