1

I'm gonna probably find another way around this, but I'm still very new to Craft and want to ask if I'm missing something obvious. This is a commerce site that needs a front-end login.

I have an account template folder with some templating that looks like this (it's an extended layout, leaving out unnecessary lines):

{# account/index.html #}
{% block main %}
    {% if craft.session.isLoggedIn %}
        {% include 'account/account.html' %}
    {% else %}
        {% include 'account/login_signup.html' %}
    {% endif %}
{% endblock %}

And an excerpt from my general.php

{# excerpt from my general.php file #}

'loginPath' => 'account',

'postLoginRedirect' => 'account',

When a logged-out user goes to website.com/account the login_signup.html page is spit out and a user can sign in (ignore the sign-up part). If they type in their info correctly, it leads to an ERR_TOO_MANY_REDIRECTS of account redirecting to account. This doesn't make sense to me, as both the login url and the post-login url point at the same path and load the same template, but the template should obviously handle the two situations differently. It should spit out the account.html template if the user is logged in, and if not, the login_signup.html template. These two template files have nothing in them right now, so it's not some other templating mistake.

If I remove either of the two config variables I presented in my general.php file, everything works but the routes I want aren't there.

I want a logged out user to visit account, get a sign in (login_signup.html) form they then use, and get redirected to account and the template will spit out the account.html template.

Edit Basically, if a user is logged in with my general.php having those two configs set to the same path (account), this always results in too many redirects:

{% block main %}
    {% if craft.session.isLoggedIn %}
        I'm logged in!
    {% else %}
        I should log in!
    {% endif %}
{% endblock %}

1 Answer 1

0

Yeah... that won't work.

Craft currently uses the URI segments to determine special path like logging in, out, etc.

So when Craft sees account as the first segment in the URI, its going to treat that as a login request and execute what's in UsersController->actionLogin(), which will see that you're already logged in, and will eventually hit this if the user doesn't have CP access permissions:

// Otherwise send them wherever postLoginRedirect tells us
$postLoginRedirect = craft()->config->get('postLoginRedirect');
$returnUrl = UrlHelper::getSiteUrl($postLoginRedirect);

Which, you've got set to account, then it rinses and repeats given you the infinite redirect loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.