Jump to content

Login/Register with Facebook Button


THshadow
 Share

Recommended Posts

I have Facebook set up on my forum to allow people to register easily with their account.

This works fine in the normal practice of things, such as clicking on the signup button and going through the flow.

I am using IP.Pages and have a public (Guest viewable) page on my site that I want to put this Facebook button on to allow them to easily click and register right from there.

How can I go about doing this, and at the same time, not display this button if they are already logged in?

 

Update

Using pages, I created a block for this button that I only show to guests which works fine. 

The content of this block is:

<a href='{$url}' class='ipsButton ipsButton_verySmall ipsButton_fullWidth ipsSocial ipsSocial_facebook'>
    <span class='ipsSocial_icon'><i class='fa fa-facebook'></i></span>
    <span class='ipsSocial_text'>{lang="login_facebook"}</span>
</a>

The issue with this is that the following doesn't get parsed because it doesn't know what to put there.

{$url}

Is there a global variable I can use that will give me the Facebook login url?

Hardcoding it like this throws a CSRF error because its missing part of the variable which is normally included on the front end.

https://www.facebook.com/dialog/oauth?client_id=2076774779217739&scope=email,user_posts,publish_actions&redirect_uri=http://domain.com/applications/core/interface/facebook/auth.php

Edited by THshadow
Additions
Link to comment
Share on other sites

I found the template for this button located here - Core > Global > Login > facebook in the main forum system.

I tried adding this to the page content but I think it crashed, got a server error when trying this.

{template="facebook" app="core" group="global" location="login" params=""}

 

Edited by THshadow
Link to comment
Share on other sites

After playing around with this, I finally got something working, although, it feels hackish.

 

{{if !\IPS\Member::loggedIn()->member_id}}
  <a href='https://www.facebook.com/dialog/oauth?client_id=2076774779217739&scope=email,user_posts,publish_actions&redirect_uri=http://mydomain.com/applications/core/interface/facebook/auth.php&state=front-{expression="\IPS\Session::i()->csrfKey"}-{expression="base64_encode('http://mydomain.com')"}' class='ipsButton ipsButton_verySmall ipsButton_fullWidth ipsSocial ipsSocial_facebook'>
      <span class='ipsSocial_icon'><i class='fa fa-facebook'></i></span>
      <span class='ipsSocial_text'>{lang="login_facebook"}</span>
  </a>
  <br />
{{endif}}

I look forward to a better suggestion to this, especially a dynamic URL variable so I don't have to hardcode it into the block like that.

Link to comment
Share on other sites

I don't know. But i'll start this job with something like that:

{{$fb = \IPS\Login\LoginAbstract::load('Facebook');}}
{{$fbLoginForm = $fb->loginForm(\IPS\Http\Url::internal(''));}}
..
{$fbLoginForm|raw}

\IPS\Http\Url::internal('') - just for error preventing. It's not using with form generation.

Anyway, you can see how this url generated in \IPS\Login\Facebook class (\system\Login\Facebook.php, loginForm method)

Edited by Upgradeovec
Link to comment
Share on other sites

5 hours ago, Upgradeovec said:

I don't know. But i'll start this job with something like that:


{{$fb = \IPS\Login\LoginAbstract::load('Facebook');}}
{{$fbLoginForm = $fb->loginForm(\IPS\Http\Url::internal(''));}}
..
{$fbLoginForm|raw}

\IPS\Http\Url::internal('') - just for error preventing. It's not using with form generation.

Anyway, you can see how this url generated in \IPS\Login\Facebook class (\system\Login\Facebook.php, loginForm method)

Thanks for the info - I will try this later today. What i have is working but is obviously not the correct way to do things :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...