verbb / knock-knock

Password protect your entire Craft website front-end with a single password
MIT License
18 stars 7 forks source link

Throws a "template not found" with default settings #34

Closed stefanmf closed 4 years ago

stefanmf commented 4 years ago

Description Installing the plugin on my site without changing any settings throws a "Template not found: knock-knock/who-is-there" error when accessing the front end.

Steps to reproduce

  1. Install plugin
  2. Log out
  3. Access site

Additional info

Additional context The site is installed in a subfolder, so the base path of the site is something like "http://domain.com/subfolder" The plugin works if I manually put "knock-knock/who-is-there" in the Custom Login Path of the plugin settings. Maybe the problem is in the way the getLoginPath() function generates the url used in _registerSiteRoutes()? The url returned by getLoginPath() is a full url ("http://domain.com/subfolder/knock-knock/who-is-there") which does not seem to work.

engram-design commented 4 years ago

I've just setup a new Craft install to test this, but wanted to make sure my settings were right. How did you install Craft into a subfolder?

I have a single site setup with the base url set to http://craft.test/subfolder/. I can visit http://craft.test/ or http://craft.test/subfolder/ and I'm getting prompted to login with Knock Knock.

Maybe my setup is different to yours? The directives in _registerSiteRoutes() should set a route relative to the current site's base URL. So it should setup a route with http://craft.test/subfolder/knock-knock/who-is-there

Maybe I don't have my web root setup correctly compared to yours?

stefanmf commented 4 years ago

Craft is installed in a subfolder on my domain, so the root folder is a completely different site. In your example, http://craft.test/ would be a different site from http://craft.test/subfolder/. I do not know if this is related to the problem, I just thought I would mention it since it seemed likely.

You mention that the directives in _registerSiteRoutes() should set a route relative to the current site's base URL. Problem is, on my setup $settings->getLoginPath() returns the full url http://domain.com/subfolder/knock-knock/who-is-there which is an absolute url, perhaps that is the problem?

In my config.php I have defined:

'siteUrl' => '//'.$_SERVER['SERVER_NAME'].'/subfolder/',
'rootUrl' => '//'.$_SERVER['SERVER_NAME'].'/subfolder/',
'assetsUrl' => '//'.$_SERVER['SERVER_NAME'].'/subfolder/'
engram-design commented 4 years ago

Thanks for the clarification - just noticed that $settings->getLoginPath() is an absolute URL, which is totally incorrect. Looking into it

engram-design commented 4 years ago

Think this should be fixed in 1.2.13 - let me know if not!