vendredi 1 avril 2016

Laravel 5 Ban users via Bican roles

I'm making a application in laravel 5.1 and I'm using Bican roles to manage the user's permissions and role names. Now I want to be able to ban my users.

So if I ban a user, the application needs to check globally the application if the user is banned. Im storing the bans in a new table outside of the users table because in that way, I can always find all the bans there were given to a specific user.

My database structure looks like this:

+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | CHARACTER_SET_NAME | COLLATION_NAME     | COLUMN_TYPE      | COLUMN_KEY | EXTRA          | PRIVILEGES                      | COLUMN_COMMENT |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
| def           | xenionode    | banned     | id          |                1 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | PRI        | auto_increment | select,insert,update,references |                |
| def           | xenionode    | banned     | user_id     |                2 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
| def           | xenionode    | banned     | banned_by   |                3 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
| def           | xenionode    | banned     | reason      |                4 | NULL           | NO          | varchar   |                      255 |                   1020 | NULL              | NULL          | utf8mb4            | utf8mb4_unicode_ci | varchar(255)     |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | expires     |                5 | NULL           | NO          | datetime  | NULL                     | NULL                   | NULL              | NULL          | NULL               | NULL               | datetime         |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | lifted      |                6 | NULL           | YES         | datetime  | NULL                     | NULL                   | NULL              | NULL          | NULL               | NULL               | datetime         |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | lifted_by   |                7 | NULL           | YES         | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
7 rows in set

Now I want if a user is banned, the user still can login, but redirects always to a view called banned.

I really don't knwo how I can do this global check in Laravel 5 in a propper way, if someone could help me out, that would be awesome!

Kindest regards

Robin



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire