I want to only an active user account with Laminas Authentication, so when status is 2 in the database the login has to proceed. With only email and password everything is working fine, how to add the status in de adapter/authentication?
I tried this part in the documentation, but did not get it working…
In my database table “users” there is a column “status”, the script I now use does work, but with a workaround.
class AuthenticatieControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
$requestedName, array $options = null)
{
$UserTable = $container->get('UserTable');
//Onderdeel van Authenticatie module om via een database tabel users te verrivieren
$adapter = new CredentialTreatmentAdapter($container->get('DbAdapter'));
$adapter->setTableName('users');
$adapter->setIdentityColumn('email');
$adapter->setCredentialColumn('password');
// Instantiate the controller and inject dependencies
return new AuthenticatieController($adapter);
}
}
AuthenticatieController->login
….
$email = $inputFilter->getValue('email');
$password = $inputFilter->getValue('password');
$this->adapter->setIdentity($email);
$this->adapter->setCredential(User::encrypt($password));
$auth->setAdapter($this->adapter);
$result = $auth->authenticate();
//Checken of account actief is (Status 2)
$userArray = get_object_vars($this->adapter->getResultRowObject());
if ($userArray['status'] != 2) {
$message = "Uw account is (nog) niet actief, activeer uw account via de email die u heeft ontvangen na het aanmaken van het account";
$auth->clearIdentity();
return ['form' => $form, 'melding' => $message];
}
//Checken of email bestaat en Password klopt (via de Laminas adapter)
if ($result->isValid()) {
$logged = true;
return $this->redirect()->toRoute('profiel');
} else {
foreach ($result->getMessages() as $message) {
return ['form' => $form, 'melding' => $message];
}
}
}
…..