2

this might be a simple fix, but it certainly doesn't seem to be.

I have built a EE-based web application, and as is part and parcel with web applications, users are required to log into the system.

With our application, users are often sent links like profile links, sort of like a social network works. However, at the moment, when users click on the links, they are required to login, and then they are brought to a generic template after logging in. I've tried using this http://devot-ee.com/add-ons/preevious but the value is coming up as blank regardless of how many times I try to use it.

Any ideas? Realistically, this is a massive deterrent for our users. If they are sent a link to a page, they need to log into the system, and then go back and click on the link in an email or via whatever other medium they were sent the link.

Any help or input would be massively appreciated. By the way, we are using standard access restrictions on this web app, which are set in the Template Manager. So if I try to go to domain.com/contacts, it will redirect me to domain.com/login and then once I login it will bring me to domain.com/home because that is our index page.

Cheers in advance, Conor

  • When they click on the link, are they be taken directly to the 'link' url, with a message on page that they need to login, or are they being redirected to a login page immediately? – nonprofit_tech Apr 11 '13 at 21:22
  • So when the user clicks on the link or tries to load a url into the browser, if they are not logged in, then it will attempt to go to the specified URL, their access will be restricted and they will be forced to go to the login page. – Conor Higgins Apr 11 '13 at 21:39
1

There are a few ways to do this, I find the easiest to be, to make the login page, available everywhere.

For example, we frequently have the login available from the Navigation Bar or one of those TopNav bars, say like Twitter. Generally, in either case, we use either CSS hide/display or an overlay window to display the login option. And have the login return them to the same page.

We've done this using Solspace's User, Authenticate, Zoo Visitor, and SafeCracker Registration. I'm certain any of the other add-ons for membership or registration will also allow you to do it as well.

Generally, speaking, if your login is available from ANYWHERE, then you don't really have to worry about re-directing the user back to where they came from. I like using FancyBox or another overlay script to provide the fields to enter in username and password, log them in, then drop them back onto the page.

Even without an add-on, you can set-up pages that require login access to display the login, when the user isn't logged in.

Using the built-in Member Login Form, see Login Form Tag. You can set-up something like:

 {exp:member:login_form return="{site_url}/{segment_1}/{segment_2}/{segment_3}"}

     <p>
          <label>Username</label><br>
          <input type="text" name="username" value="" maxlength="32" size="25">
     </p>
     <p>
          <label>Password</label><br>
          <input type="password" name="password" value="" maxlength="32" size="25">
     </p>
     {if auto_login}
          <p><input type="checkbox" name="auto_login" value="1"> Auto-login on future visits</p>
     {/if}

     <p><input type="checkbox" name="anon" value="1" checked="checked"> Show my name in the online users list</p>
     <p><input type="submit" name="submit" value="Submit"></p>
     <p><a href="{path='member/forgot_password'}">Forgot your password?</a></p>

 {/exp:member:login_form}

This form combined with the page logic like

{if logged in}
   {embed="include/mypage"}
{if:else}
   {embed="include/login}
{/if}

Should work.

| improve this answer | |
  • This is definitely a very good and plausible solution, though it's not exactly what we are able to use as it takes a lot of reworking on each template and we have tonnes of content on the app. We found a great solution though which I'll post in a sec as an answer. Thanks for your input though! – Conor Higgins Apr 12 '13 at 10:10
1

Found a great solution this morning. We are now using stash to set values before pages are redirected and then to get the value on the login template. It is fairly similar to nonprofit_tech's suggestion above, except this is all handled on a single page which is being set for all our redirects. So if a user has no access to a page, they are sent to the site's index. Then if they are logged out, set a stash variable, and redirect them to the login template.

{if logged_out}
    {exp:stash:set name="preLoginUrl" scope="user" save="yes"}{site_url}{segment_1}{if segment_2}/{segment_2}{/if}{if segment_3}/{segment_3}{/if}{/exp:stash:set}
    {redirect='login'}
{if:else}
    ...perform a bunch of routing here...
{/if}

Then on the login template (using a zoo visitor login form):

{exp:zoo_visitor:login_form error_handling="inline"}
                    <input type="hidden" name="RET" value="{exp:stash:get name="preLoginUrl" process="inline"}" />

                    {if "{error:login}" != ""}
                    <div class="content dashed-bottom error-holder">
                        <span class="tag danger">{error:login}</span>
                    </div>
                    {/if}
                    <div class="fieldset-holder cf">
                        <fieldset>
                            <label>Email</label>
                            <input type="text" name="username">
                        </fieldset>
                        <fieldset>
                            <label>Password</label>
                            <input name="password" type="password">
                        </fieldset>
                        <fieldset class="inline grid-33">
                            <label for="loginButton" class="button block primary"><i class="icon-key"></i><span>Sign In</span>
                                <input id="loginButton" class="hide-submit" type="submit" value="submit">
                            </label>
                        </fieldset>
                        <fieldset class="inline grid-66 text align-right">
                            <div><a href="{site_url}login/reset/" class="link">Forgot your password?</a></div>
                        </fieldset>
                    </div>
                    {/exp:zoo_visitor:login_form}

We tried everything from cookies to using php referrer headers and nothing worked apart from stash.

Hopefully this helps someone else out.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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