Sending a specific record to an anonymous guest

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Sending a specific record to an anonymous guest

Post by wilmira » 2023-05-11 23:53

Hello community,

When sending a URL linked to a specific record to an anonymous guest, I need that guest to only see that record, that is, preventing the guest to see the whole table.

In other words:

http://localhost/Filesharing/items_de_l ... em_item=ID is the only URL format the guest can see.
Any other without ID: http://localhost/Filesharing/items_de_l ... item_item= , or http://localhost/Filesharing/items_de_lista_view.php is not accepted or should redirect to home page or simply show nothing.

The anonymous group is configured to see all records of items_de_lista table, cause anybody can receive a URL with any ID available, but nobody should see the whole table.

Also, as you can figured it out, I had hide all the links in nav menu and home menu, so if redirected to home, nothing will be shown.


Thanks in advance for your help!
Attachments
sharefiles3.gif
sharefiles3.gif (180.62 KiB) Viewed 2729 times

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Sending a specific record to an anonymous guest

Post by onoehring » 2023-05-12 05:27

Hi

this might work:
You can use the _init function in the table: There
- check if it's the anonymous group
- if it is the anonymous group, display the detail view of the page. Something like $options->... (I don't remember, look it up the the documentation)

You can open a page using $POST, thus the user will not see the ID, but to display the data, you will need to check for the $POST variable and use this as "selectedID".

But I do not understand the problem, why a user should not be able to see the ID - if he can see the whole record. This does not make any sense to me. You should reconsider this probably.

You could also implement something like a TAN: Use another table, store some TAN there which is associated with the ID of the record. If the user calls that URL with a correct TAN, you forward him to the page with the record in question. Advantage here: You can log, when and how often this record was seen and you can easily destroy the TAN and make the link unusable, in other words, timelimit it.

just some ideas

Olaf

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Sending a specific record to an anonymous guest

Post by wilmira » 2023-05-12 20:10

Hello Olaf,

Thank you for your help and let me clarify the problem: The anonymous user should see the ID, the problem appears when that user delete on purpuse or by mistake that ID, or the administrator who sent the link to the anonymous user do not copy the whole link, in that case, the anonymous user will see the whole table, with records not sent to him, that is why I need to redirect to the homepage that has not any link to any table) if, by chance, the ID is removed or the URL was sent incomplete.

So seen the ID is not the problem, the problem is manipulating the ID or sending the URL incomplete (without ID).

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Sending a specific record to an anonymous guest

Post by wilmira » 2023-05-12 20:13

*seen = to seee

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Sending a specific record to an anonymous guest

Post by onoehring » 2023-05-13 06:38

Hi,

first of all, I strongly believe, if someone is not capable of clicking on a link or copying a link there is not much a developer can do.

Still: you can check if an existing ID was given (probably in \filename.php function _init). If there is no valid ID just forward the user to a different page where you give some explanation that something was wrong (maybe explain that the ID should be there was well ...).
For PHP redirect check for example this: https://stackoverflow.com/questions/768 ... php#768472

Olaf

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Sending a specific record to an anonymous guest

Post by wilmira » 2023-05-13 14:13

Hello again Olaf,

Maybe I explained myself in a wrong way. The user have to click the URL the administrator have sent him, but the user as well can manipulate the ID manually. If he does that, as it is now, he will see the whole table, not just the record the administrator have sent him. So he will be able to see data that was sent by the administrator to other users.

For example. If the anonymous user click over the url sent to him and the URL contains the ID=5, he will see data that has been sent to him exclusively, but if he delete the ID in the URL, he will see the whole table, with data that has been sent to all the anonymous users.

I found a way to solve it by adding a field in that table that will contain a ramdom generated code, then create a default filter for that table. The filter will ask for the code sent to the anonymous user and with that code he will be able to retreive the data and only tha data sent to him.

With this configuration, the user only see the data sent to him, the url shown is only the table_view.php. You can click on the refresh button of the browser and nothing change. But if you select the URL in the browser and press enter, then the whole table is shown, so this is not a definitive solution.

I will check the info you have sent me. Thanks again for your help!

Wilfredo

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Sending a specific record to an anonymous guest

Post by onoehring » 2023-05-15 07:22

Hi Wilfredo,

I think you answered your question yourself.

Simple solution (if it works):
Did you try to have an primary key that is NOT integer, autoincement? If this works, the user will not be able to guess a complex key (complex=long and random).

I think not using the primary key function might cause problems in AG (lookup fields), so you may think about it/this:

Second suggestion (if 1st does not work)
Give your table a new "secret" column. This column contains some unique identifier and is not visible to the user - neither in table view, nor in detail view. The data in there is being generated by your code .. whenever you like (creation / edit / time based via some cron job) etc. This column is much like the TAN I suggested before.

Now, give the user a link which identified that column:

Code: Select all

https://yourDomain.com/seeRecord.php?ID=HereYourSecretColumnContentsThatIdentifiesTheRecord
If you do this (linking to a non AG file) you could of course have a seperate table which holds the secret (HereYourSecretColumnContentsThatIdentifiesTheRecord) combined with an AG tablename.
Like so, the script seeRecord.php will grab this code and forward to the specified record of the table.

If you link to the table directly, and it does have a primary key that is easy to guess (straight number starting from 1) perform another check when the anonymous group tries to access a record: Test, if the secret key matches to the ID given ... then the link needs to hold two parameters:

Code: Select all

https://yourDomain.com/your_appginitable_view.php?ID=99&mySecret=HereYourSecretColumnContentsThatIdentifiesTheRecord
In this case the anonymous user tries to access record with ID 99 in table "your_appginitable". Your application needs to check, is the hidden/matching column contains "HereYourSecretColumnContentsThatIdentifiesTheRecord" for record 99.

As AG is not capeable to hide columns from certain user groups, the above does not work as is. You will need to implement a third table (as also mentioned above) which the anonymous does not have access to, but you have. There you define which record (=which ID) of "your_appginitable" can be accessed with which secret.
Screts-Table fields:

Code: Select all

ID (PK, int, autonumber)
tablename (char)
recordid (same as the primary key in your table is)
secret (char)
Of course, this table could be filled by hand - or automatically. Maybe it's an idea to generate the link that you want to send to the user auotmatically as well each time, when the record is updated (or created). The link could be saved in another field of the table. Or, build yourself a function to create a link when it's needed.

Olaf

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Sending a specific record to an anonymous guest

Post by wilmira » 2023-05-15 15:21

Hi Olaf,

Thanks again for your help. I will try you suggestions and let you know later.

Wilfredo

Post Reply