Skip to content
Advertisement

Allow users with is_request 1 to not log in

I am currently working on a system where people can submit a registration request. The admin will need to accept the request in order for the user to be able to sign in. In my database, I have a field called is_request and with every registration this field is set by default to 1 (is set by default to 1 in the database) , meaning yes. When a user with this field set to 1, tries to log in, they will need to be notified that their account has not yet been activated. How can I accomplish this?

When the user tries to register the following happens:

JavaScript

And when the admin in the backend “accepts” the request the field is_request will be set to 0 and the user needs to be able to sign into the app.

The login controller looks like this

JavaScript

Update:: DB Table enter image description here

Advertisement

Answer

You could create an global middleware that checks if the user is accepted or not:

JavaScript

This middleware will log out any authed user that aren’t accepted and redirect them to a route of your choice.

Change auth()->user()->isAccepted to an attribute or method that contains information about the accepted-status.

If you want the middleware to run at every request, you can add it as a global middleware by adding it the the $middleware-array in app/Http/Kernel.php.

You can read more about middleware and how to create them in the docs: https://laravel.com/docs/master/middleware

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement