0
votes

I created a function in a controller and its corresponding view (called 'feedback') for a page that does not require authentication and the URL looks like this:

http://[DOMAIN]/products/feedback/11351/6673/24678/2/rt6a513gr45255hrt563443h2463hd63

The URL works without requiring authentication and everything is perfect. This URL contains a form that the visitor needs to fill out and then this data goes straight to the database. The problem is that when the form is submitted, if the visitor has not logged in, then authentication is required and the process breaks there in a way that the data from the form is never sent to the database. What I want is for this URL not to require authentication, never, not when the page and form are loaded (this part already works fine) nor when the form is submitted (this is what I need to fix because when the submit button is clicked, authentication is immediately required).

UPDATE 1:

I already tried including the following code in `app/controllers/products_controller.php:

function beforeFilter(){
    ........................
    ........................
    ........................
    parent::beforeFilter();
    $this->Auth->allow('feedback');
}

My idea was to exclude the feedback action from the authentication requirement. I tried this based on the documentation I found at https://book.cakephp.org/1.3/en/The-Manual/Core-Components/Authentication.html:

For example if we want to allow all users access to the index and view methods ( but not any other), we would do the following:

function beforeFilter() { $this->Auth->allow('index','view'); }

I found the same suggestion CakePHP Bypass Auth component to bypass Auth component in CakePHP.

1
What do you mean by this data goes straight to database? Do you have action in cakephp that handles the form submit and it needs to skip auth check?Alex
What are you doing to allow the page with the blank form to be loaded without authentication? Is the controller and action for the data submission the same as that page?Greg Schmidt
Yes @Alex. I have an action in CakePHP that handles the form submit and it needs to skip the auth check. What I mean by this data goes straight to the database is that the visitor can initially visit the URL without requiring authentication and what I want is that the data filled out in the form can go directly to the database when when user clicks the submit button, without requiring authentication, meaning skipping auth check.Jaime Montoya
@GregSchmidt I am doing a survey. I do not want to require authentication because the URL is already encrypted in such a way that only someone with a valid URL would be able to fill out the survey and for that reason, authentication should not be required. The controller and action for the data submission is the same as that page in the http://[DOMAIN]/products/feedback/11351/6673/24678/2/rt6a513gr45255hrt563443h2463hd63 URL, but after filling out the form correctly, I redirect the user to the home page.Jaime Montoya
$this->Auth->allow('feedback'); should certainly work. If you didn't have this previously, I was wondering how it was that you got the blank form to skip authentication.Greg Schmidt

1 Answers

0
votes

I achieved it by including products/feedback to my exception array in the file app/app_controller so that whenever the visit applies to the URL for which I want authentication to be bypassed, this code will do the magic: $this->Auth->allow('*');. It works for me correctly now as I wanted it.