Custom login conditions

Hi, I implemented the standard Auth in my project.
Means user need to login with email and password.
But I need a 3rd criterion to login.
In DB there is a field with status.
During login I want to check if status = 2. If yes, user can log in, if not → access denied.
Can someone tell me where to put this check?
Thanks

You want to use the finder option when creating the ORM Resolver, and specify a finder that adds the status check.

2 Likes

In your src/Application.php you add a “finder” to the getAuthenticationService method:

        $authenticationService->loadIdentifier('Authentication.Password', [
            'fields' => [
                'username' => 'username',
                'password' => 'password',
            ],
            'resolver' => [
                'className' => 'Authentication.Orm',
                'userModel' => 'Users',
                'finder' => 'enabledUser'
            ],
        ]);

In the model UsersTable you define, what enabledUser means, e.g.

    public function findEnabledUser(Query $query, array $options): Query
    {
        return $query->where(['Users.enabled' => true, 'Users.group =' => 'user']);
    }

Hey hasentopf, I was not aware that there is some option to realize this topic in UserTable. Thanks for hint.
For now I did the solution what was mentioned by Zurulu.
But I will try your solution

We’ve both told you the same thing, just one with documentation and one with an example.

2 Likes