Login popup + auto close after login

Post

Posted
Rating:
#5080 (In Topic #1145)
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’

...with redirection

I have some content that only shows to users who are logged in. If they are a guest, it instructs them to login to view the content. My hope is to have an overlay popup linking to the login page, and once the user logs in, the popup closes and the original page redirects to itself (basically refreshing it to hide the message about needing to login).

When I tried to accomplish this using faux_open() or open_link_as_overlay(), the popup doesn't close itself after the user logs in. Instead the popup redirects itself and stays open.

A temporary work around that I am using for now is just a message to guests linking to the login page (and leaving the current page entirely), but then I have a redirect parameter in the URL to bring the user back to the current page after login. But I'm trying to make my site easier to use in the sense that users don't have to leave current pages to do something else, just to come right back to it. I prefer it all be done on the same page!
Online now: No Back to the top

Post

Posted
Rating:
#5099
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Hi Joe,

This is hard to follow.

Normally when access to a page is denied, it would automatically be a login page. But it sounds like you are trying to deny access via Tempcode inside a page.

I'm not sure I fully understand the flow. You said "an overlay popup linking to the login page". Are you saying that there's a page A, which has a link to open a page B in an overlay, which has a link to open to login page L in that same overlay, and then you want the overlay to self close somehow.
I'm not sure why you'd have a page B before the login page L, and not just go straight from A to L. However, I'm not sure that really changes the problem at hand.

The overlay should actually close itself. The default LOGIN_SCREEN template's form has target="_top", which should cause the overlay to be implicitly closed because it's posting into the main window not the overlay. That behaviour is already in active use in Composr, as there's a login link in the default footer that does this. So long as the login link you're triggering has a redirect parameter pointing back to page A, and the default login template's form functionality unaltered, it should work fine.

Default login link in footer:

Code

<a onclick="return open_link_as_overlay(this);" href="{$PAGE_LINK*,_SELF:login{$?,{$NOR,{$GET,login_screen},{$_POSTED},{$EQ,{$PAGE},login,join}},:redirect={$SELF_URL&*,1}}}">{!_LOGIN}</a>


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#5101
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
The page is visible to all users, but some content is blurred out from view to guests (neat little CSS + Tempcode trick I made into a Comcode tag). This blurred content informs the user that they must login to view that section of information.

So, I was hoping that I could have a link right there within the blurred content, linking to the login page via an overlay, then redirect the user back to the original page which would remove the blur effect, thus showing the content to the user after they've logged in.

I'll try that little snippet of code you gave me inside my template later, but as of right now, the popup doesnt self destruct as you claim it should. I suppose something in that code you supplied is what does the trick.

Currently, I believe what I'm using is just a simple…

Code

<a &#111;nclick="return open_link_as_overlay(this);" href="{$PAGE_LINK*,:login:redirect={$SELF_URL*}}">{!_LOGIN}</a>

Hope that explains it better!
Online now: No Back to the top

Post

Posted
Rating:
#5102
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Ok. Check the target attribute of the login form, perhaps you changed that with your templating.
If that's set to _top I can't see how it wouldn't work.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#5103
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’

Chris Graham said

Ok. Check the target attribute of the login form, perhaps you changed that with your templating.
If that's set to _top I can't see how it wouldn't work.

Using _SELF worked, but I didn't bother trying _TOP.

However, now I'm running into another issue with {$SELF_URL}: it's acting very strangely.

I have a link with a custom URL parameter, mysite.com/index.php?page=mypage&param=foo
The login href is written in my template like so: {$PAGE_LINK*,_SELF:login:redirect={$SELF_URL*}}
When hovering over the link, there seems to be some interference when {$SELF_URL} is inside {$PAGE_LINK} because the link is shown very oddly:

Code

https://mysite.com/index.php?page=mypage&param=foo&redirect=https&//mysite.com/index.php?page=mypage%26amp%3Bparam%3Dfoo

Because there's a & symbol after https, this just redirects to a not found as it's interpreting https to be an actual Comcode page.

However, if I seperate {$SELF_URL} from {$PAGE_LINK}, like so:
{$PAGE_LINK*,_SELF:login}&redirect={$SELF_URL*}

..things seem to link properly, BUT…even though hovering over and clicking the link does in fact append the &param=foo to the redirect parameter, once I log in and the actual redirection happens, it doesn't keep it appended.

So to sum up my questions:
1). Why does using {$SELF_LINK} within {$PAGE_LINK} interfere with showing the URL? Strangely it doesn't seem to have this problem in that footer template you mentioned earlier.
2). Do I need to change my custom URL param to keep_param=foo in order for Composr to keep it appended?
Online now: No Back to the top

Post

Posted
Rating:
#5106
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
Ok, I see that you used {$SELF_URL&*,1}, this seems to work without interference. So, scratch my previous post! It's all working now.
Online now: No Back to the top

Post

Posted
Rating:
#5123
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Right, & adds the appropriate URL-escaping.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#5216
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
Using faux_open() to open a login popup doesn't self destruct after logging in. No matter how I write it out, it never works.

Code

<button &#111;nclick="faux_open('{$PAGE_LINK*,_SELF:login{$?,{$NOR,{$GET,login_screen},{$_POSTED},{$EQ,{$PAGE},login,join}},:redirect={$SELF_URL&*,1}}}','','width=500,height=500,status=yes,resizable=yes,scrollbars=yes');" rel="nofollow" class="grad_button">{!_LOGIN}</button>

It's not a big deal though because I can just go this route:

Code

<a &#111;nclick="return open_link_as_overlay(this);" rel="nofollow" href="{$PAGE_LINK*,_SELF:login{$?,{$NOR,{$GET,login_screen},{$_POSTED},{$EQ,{$PAGE},login,join}},:redirect={$SELF_URL&*,1}}}"><button class="grad_button">{!_LOGIN}</button></a>

Don't know if it's valid markup but it works! :thumbs:
Online now: No Back to the top
1 guest and 0 members have just viewed this.
Back to Top