Welcome Guest, Not a member yet? Register   Sign In
Basic usage how-to for Shield authentication

I have Shield installed. Registration is working. 

Need simple instructions on how to implement for basic operation:

1. How do I set up user management: add, modify and delete accounts, assign and modify group?

2. How do I restrict access to individual pages and parts of pages?


Hello @Tbronson , everything you need is in the documentation.

Quote:1. How do I set up user management: add, modify and delete accounts, assign and modify group?
Have you read Shield?
Have you seen the questions in section discussions?
If you have read, can you tell us which part is unclear for you?

Quote:2. How do I restrict access to individual pages and parts of pages?

You need to use filters, here's how to write filters. You can also refer to GroupFilter for more guidance on filters.
Do you need more explanation?

(This post was last modified: 08-02-2022, 02:17 AM by Tbronson.)

Thanks! My question was poorly worded. I'm looking for working examples of implementation. I guess Shield is so new, maybe none have been done yet? 

I'm not a coder, and I learn how to use best by starting with working examples. For CI4, I took the code from a "Simple CRUD project for CI4" article, and modified from there by reading the CI docs.

(I did read the Shield and related CI docs. I understand how it's implemented--the set-up seems to be pretty much the same as Laravel authentication, which I'm familiar with, as far as filtering pages in routes.)

Quote:maybe none have been done yet? 

Yes, what you are looking for is not currently in the documentation.
We previously had a request from someone for more clarification in the documents, which led to good changes in the documents.

I think you are the first person to look for practical examples in the implementation and use of the shield.

If the requests are suitable in this context, it seems possible to do this request.

Anyone, if you agree with the request, please let me know.

I was also looking for a way to remove users from Shield.

All I found was in the discussions this thread https://github.com/codeigniter4/shield/discussions/249 with a link to the migrations to setup the tables for users.

Given there is more than one table that references a user, it might be worth coming up with an SQL query that removes all records in the database related to a user.

Other than the users table (id), the foreign key is user_id.

Users Table
Auth Identities Table
Auth Login Attempts Table
Auth Token Login Attempts Table
Auth Remember Tokens (remember-me) Table
Groups Users Table
Users Permissions Table

From investigating, it seems when the tables were setup, it would be convenient to add a constraint of ON DELETE CASCADE so that user_id foreign key references in other child tables will be deleted in other tables when you delete the user in the users table.

I queried all the constraints in my database and cannot find any DELETE CASCADE so this is not setup.

In that case you will need to run multiple queries to remove the user from all tables.

For example, in phpmyadmin, I ran a SQL command that removes all users with an id in the users table thats more than 1. You could replace > 1 with a = 2 for example, to remove the user with id 2.

DELETE FROM users WHERE id > 1;
DELETE FROM auth_groups_users WHERE user_id > 1;
DELETE FROM auth_identities WHERE user_id > 1;
DELETE FROM auth_logins WHERE user_id > 1;
DELETE FROM auth_permissions_users WHERE user_id > 1;
DELETE FROM auth_remember_tokens WHERE user_id > 1;
DELETE FROM auth_token_logins WHERE user_id > 1;

Theme © iAndrew 2016 - Forum software by © MyBB