ryan

PW 3.0.69 plus PW Login for Facebook

Recommended Posts

This week's version of ProcessWire on the dev branch is 3.0.69 and it includes several minor bug fixes. This week's post focuses in on a new module released today called Login for Facebook, which I think many might find useful, and we've got all the details here:

https://processwire.com/blog/posts/pw-login-for-facebook/

  • Like 18

Share this post


Link to post
Share on other sites

Thanks for this module!!!

Quote

You can choose to have all Facebook logins map to the same user account, but the default behavior is to have it automatically create new ProcessWire user accounts for each Facebook user.

I am wondering, because "mapping to the same user account" is always disabled. Creating a new user account for each Facebook login user will lead to problems in my case, because I dont allow to register an email address twice. (fe. same email address on Facebook Login and default login). This is because I have a "forgot password" link on my frontend where you have to enter the email address only to get an email with a new password. If there are two equal email addresses in the DB this leads to problems.

I dont want to rewrite it to enter the username in addition to the email address, because sometimes people forget username and password.

So how can I map all FB Logins to one user account?

It will also be a great addition if it would be possible to connect facebook logins to the default user account.

Fe. if someone is logging in with FB and the same email address is also stored in the user DB, then the user will be asked if he wants to connect his FB Account with the default account.

If "yes" then the user will be asked to enter his password to verify this is his own default account. If the password is entered correctly than the FB Login Account will be connected to the default account.

Best regards Jürgen

 

Share this post


Link to post
Share on other sites

I found this line of code in config.php line 131:

$f->addOption(0, $this->_('Make all Facebook users point to the same ProcessWire user'), array('disabled' => 'disabled'));

Should I remove the disabled array to make it work or is there another possibility without changing the code?

Best regards

Share this post


Link to post
Share on other sites

Is anyone else getting this error?

This error occurs in two scenarios.

1. Currently logged into facebook. Selecting to login using facebook from web site. Immediately displays this error.
2. Not logged into facebook. Selecting to login using facebook displays the facebook login form. This error is displayed after logging into facebook.

fb-login-err.jpg.e39243e919d9cbdefb319657ec2bba2b.jpg

Share this post


Link to post
Share on other sites

@rick What has been logged to /site/assets/logs/errors.txt (also exceptions.txt)? It can help you pinpoint the origin of the error.

EDIT:

Hmm. I think after authorization with FB, it redirects back to your public endpoint with a token code, but it seems like something about that page or FB module causes error to be thrown

  • Like 1

Share this post


Link to post
Share on other sites

I removed the login code on the site and the 500 error is no longer present. However, the only log entries are similar to that included below.

I changed the mapping of facebook picture field to pw image field in module settings.

The error and exceptions logs continue showing this error...
 

Quote

 

Error: Exception: Item added to ProcessWire\Pageimages is not an allowed type (in /.../wire/core/WireArray.php line 259)

#0 /.../wire/core/Pagefiles.php(326): ProcessWire\WireArray->add(Array)
#1 /.../wire/core/Pageimages.php(54): ProcessWire\Pagefiles->add(Array)
#2 /.../wire/modules/Fieldtype/FieldtypeFile.module(256): ProcessWire\Pageimages->add(Array)
#3 /.../wire/core/Page.php(942): ProcessWire\FieldtypeFile->sanitizeValue(Object(ProcessWire\User), Object(ProcessWire\Field), Array)
#4 /.../wire/core/Page.php(809): ProcessWire\Page->setFieldValue('avatar', Array, true)
#5 /.../site/modules/LoginFacebook/LoginFacebook.module(587): ProcessWire\Page->set('avatar', Array)
#6 /.../wire/core/Wire.php(386): ProcessWire\LoginFacebook->___updateUser(Object(ProcessWire\User), Array)
#7 /.../wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___updateUser', Arra

This error message was shown because: you are logged in as a Superuser. Error has been logged.

 

Attempting to save the user's facebook picture to an image field fails with the above error.

Creating and adding a text field to the user template, and mapping the facebook picture to that field does not display an error (log in is successful), but no data is stored in the text field. There is no picture_url field as shown in the blog post., only picture is available in settings.

Attempts to dump the $facebook variable to a log file or echo'd results in a 500 error.

The server is running other PW (3.0.62) sites (no facebook login module) without issues.

I'll get it sorted eventually. I was just curious if anyone else had experienced this problem so I can tell where i am pulling another newbie stunt.

 

Share this post


Link to post
Share on other sites

Facebook doesn't let you pull images if you aren't logged in. Meaning, only the client side can pull images, the server side cannot (meaning, ProcessWire cannot since Facebook blocks it). So if you are going to use picture or picture_url (or other images), you have to refer to it directly in an <img> tag using the URL facebook provides, rather than trying to pull a copy and store it in PW. 

  • Like 2

Share this post


Link to post
Share on other sites

Hi @ryan,

Figured this is a better place to post this question;

Im using your facebook login module, works as a charm.
But, when I have a link provided on my facebook account, and try to login within the facebook web-view (clicking link on the facebook page on mobile).

Im getting a 'Invalid request (no Facebook state)' error.

Any idea how to solve this?

Thanks in advance.

 

Share this post


Link to post
Share on other sites

I'm having hard time getting this to work.

I've setup the module with App ID and App Secret. The needed script is added in the _main.php. The App itself is public and both the Site URL and App Domain match. Yet all I get upon entering the "mysite.com/login-facebook" is:

Quote

Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.

I've setup multiple Facebook Apps before, but I've never run into this problem before. Does anyone have any experience with this?

Share this post


Link to post
Share on other sites
On 3/19/2018 at 10:54 AM, Hurme said:

I'm having hard time getting this to work.

I've setup the module with App ID and App Secret. The needed script is added in the _main.php. The App itself is public and both the Site URL and App Domain match. Yet all I get upon entering the "mysite.com/login-facebook" is:

I've setup multiple Facebook Apps before, but I've never run into this problem before. Does anyone have any experience with this?

I'm having this problem too - have you figured it out yet? I'm wondering if Facebook have changed something their end as the instructions for setup don't quite tally with what I'm seeing on the App configuration screen.

Share this post


Link to post
Share on other sites
Posted (edited)

Ok - I think I've got this half-way solved.

I found a similar discussion on this site: https://forum.bubble.is/t/solved-fb-login-domain-problem/3267/36
March 2018 Facebook have changed their app policy to use Strictmode for redirect URI's. 

So you need to enter 

https://YOURDOMAIN.COM/login-facebook/

into the 'Valid OAuth Redirect URIs' field. I think you probably also now need be using https to make it work.

So I get the correct FB authorisation screen when you visit the /login-facebook page.

The remaining problem now is that the redirect after FB authorisation isn't working. I get a 500 error - FB seems to be trying to send me back to https://YOURDOMAIN.COM/login-facebook/ rather than the page I've chosen in the module settings. Any ideas?

Edit: The above works fine - I was trying to map the FB profile image field direct to a ProcessWire image field which you can do and this was causing the error.

Edited by Guy Incognito
Resolved issue in my previous post
  • Like 2

Share this post


Link to post
Share on other sites

Well, in our case all the settings were all correct.

We solved the problem by switching to an another web host, and it started working right away. Was the problem because of poor work on facebook's end or the host's is anybody's guess.

Share this post


Link to post
Share on other sites
On 13/8/2017 at 2:14 PM, Juergen said:

I found this line of code in config.php line 131:


$f->addOption(0, $this->_('Make all Facebook users point to the same ProcessWire user'), array('disabled' => 'disabled'));

Should I remove the disabled array to make it work or is there another possibility without changing the code?

Best regards

@Juergen, I think that option is available in the module configuration in the admin and it just means that a single user account would be created and every FB account would map there.

I'm having the same issue though: using the Login for Facebook and the Login/Register modules together results in duplicate accounts for the same email address.
If someone already registered their email address and later logins with Facebook, the module creates another user with the same email address, rather than map the FB account to the existing user account.
Since the Login/Register module is already integrated with the FB module (it outputs a login link automatically if the FB module is found), it would be a great idea to integrate the two modules even further.

The front end login form uses email rather than username on my site so duplicate email addresses are an even bigger problem.

Any idea how to get around this?
The site is selling tickets, it would lead to confusions and lost orders because of this.

  • Like 1

Share this post


Link to post
Share on other sites
On 10/12/2017 at 8:38 PM, sirhc said:

Im getting a 'Invalid request (no Facebook state)' error.

Hi @sirhc- do you solve this in the end? Have the same error on a site and can not figure it out.

Share this post


Link to post
Share on other sites

Hi,

I try to make a hook for adding the new user in the Mailchimp list using the module "Subscribe To Mailchimp" by @daniels.
This code doesn't work. I didn't understand what facebook fields I should use and if I made any other mistakes. Someone can help me please. Hook still to be hard to learn! 😞

wire()->addHookAfter('LoginFacebook::createNewUser', function($event) {
		$u = $event->arguments[0]; // get user object

		$mc = $modules->get("SubscribeToMailchimp");
		$email = $u->email;
		$name = $u->$userName;
		$country_title = $u->$country_title;
		$subscriber = [
		  'FNAME' => $name,
		  'MMERGE4' => $country_title;
		];
		$mc->subscribe($email, $subscriber);
    }

});

Also, I would like to add this condition: if the user makes a new registration, the privacy checkbox should automatically be marked. 

 

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.