Hi,
I am using a single page to display both a “application” form and a “sign in” form (sign in form will only work for users granted a role of “participant”, the application form creates a user with role of “applicant”). They work fine apart from an issue with the error messages. If I try to sign in using the sign in form, with a correct email but incorrect password, I get the error “The passwords do not match”, rather than one about an incorrect password. I am not sure where I have gone wrong here - below is my controller file. If anyone has any thoughts that would be great.
<?php
return function ($kirby) {
// Set variables for responses
$error = null;
$success = null;
$signInError = null;
// Processing a new application
if($kirby->request()->is('POST') and get('application')) {
try {
$password = esc(get('password'));
$validate = esc(get('validate'));
if(v::same($password, $validate)) {
$kirby->impersonate('kirby');
$user = $kirby->users()->create([
'name' => esc(get('name')),
'email' => esc(get('email')),
'password' => esc(get('password')),
'language' => 'en',
'role' => 'applicant'
]);
$success = 'Congratulations ' . $user->name() . ' on a successful application. We will be in touch shortly.';
} else {
$error = 'Please note, passwords must be identical!';
}
} catch(Exception $e) {
$error = $e->getMessage();
}
}
if ($kirby->request()->is('POST') && get('signin')) {
// try to log the user in with the provided credentials
try {
$kirby->auth()->login(get('email'), get('password'));
if (($user = $kirby->user()) && $user->role()->id() === 'participant') {
go('/');
}
else {
$signInError = 'Please note your application is being processed';
}
} catch (Exception $e) {
$signInError = $e->getMessage();
}
}
return compact('error', 'success', 'signInError');
}
?>