Forums

Social Login and Register

BNDragon 14 Oct, 2014
Hello everyone,

I want to create a registration form and a login form that uses social networks (facebook, google +, linkedin, and twitter).

The normal registration form is working perfectly, the problem is to insert social networks.

To be honest, I've done some research on integration and found some API, but I can not understand how they work.

The idea is when the user click a social network button, for example facebook, if he is already registered, log in, if not already registered, go to the registration form and some of the fields are already filled with data from social network (eg. name, email ...), because then the profile fields will vary according to his profile, so I need the user to select their profile, hence can not use a plugin for social Login.

Can anyone help me? Or direct me to a good toturial well detailed, step by step, so that can do the integration?

Thanks in advance,
BN
GreyHead 15 Oct, 2014
Hi BN,

I'm a bit confused about how you want this to work. . . . "if he is already registered, log in" . . . is that Log In to your site, or to FaceBook, etc?

I'm also not sure if it is possible. . .

Bob
BNDragon 15 Oct, 2014
Hello Bob,

I'll try to explain myself better.

Imagine a user who comes to my site for the first time.
When you click the "Sign In" menu, the registration form will appear.
So far so good. What I want to do now is add the ability for the user register with social networks.

There are many plugins for this, it is true, but the user must choose his profile because fields to fill his profile will vary depending on the chosen profile. For example, the Engineering Profile, will not have the same fields as the Company Profile.

So I can not use existing plugins.

In the end, what I want is that when the user click on the social network button, the fields of my site is populated with the values โ€‹โ€‹of the chosen social network, but without automatic recording, so the user is forced to choose which one is his profile.

I hope you understood me this time Bob, the rest on first topic are a few more features that I want to implement, but now, I would really like to implement this one.

Thanks in advance,
BN
GreyHead 16 Oct, 2014
Hi BN,

I suspect that is not going to work - as far as I can see FaceBook for example has a Registration API but all that does is to confirm that the person exists - FaceBook doesn't pass you any information about the person at all.

Bob
BNDragon 16 Oct, 2014
Hi Bob,

Thanks for your reply.

Please, see this site http://www.phpclasses.org/
Try sign-in (on-top) and use a social button, and you can see what I want.

Thanks,
BN
BNDragon 16 Oct, 2014
Sory for double post,

But I forgot to say what happen in there.
When you click on Register, you go to a form that you can fill de fields with your data, or use a social button.
When click a social button, it redirect you to other form with pre-populate form with data from a choosen Social Network to confirm your data.
Max_admin 16 Oct, 2014
Hi BN,

I think that what you need to do is explained here:
http://stackoverflow.com/questions/14050528/auto-fill-my-custom-form-using-facebook-data

So maybe you can just use this code in a "load Javascript" action after adding your appid..etc

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 17 Oct, 2014
Hi Max,

It is exacly what I need!
I'll try it after lunch and then I let you know the result.

Thank you๐Ÿ˜‰
BN
BNDragon 24 Oct, 2014
Hello everyone,

Well Max, the link did not work well for me, but took me a few more links, and next thing I knew I was having a very good toturial with an example of HybridAuth.

I could understand and I put it to work locally, my question is: how can I integrate it with GK5?

Can help me replicate the form?

I leave here with a Zip code HybridAuth I have, with some changes pequnas (put some pictures on the links and whenever the user enters a social network unregistered redirects to "complete_registation").

The log folder is this directory "... \ HybridAuth \ E \ SS".

I'll try to implement, or think of a way to do it at least, I hope they can help me though.

Thanks in advance,
BN
Max_admin 26 Oct, 2014
Hi BN,

on the official page there are some PHP examples, you can use the code inside a "custom code" action as long as the files are included:
http://hybridauth.sourceforge.net/

There are also some plugins for 3rd party apps and Joomla is listed, so you may be able to find something to do that on your site quickly ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 26 Oct, 2014
Answer
1 Likes
Hi BN,

I hada quick look at this yesterday but didn't get as far as building a working sign in.

a) I added the hybridauth folder from the distribution package to the /components/com_chronoforms5/extras folder on my site.

b) I edited the config.php file to set the base_url like this
		"base_url" => JURI::root().'components/com_chronoforms5/extras/hybridauth/',


c) I copied the code from the Simple Sign-In with Twitter example and changed lines 5-7 to
// change the following paths if necessary
$path = JPATH_SITE.'/components/com_chronoforms5/extras/hybridauth/';
$config   = $path.'config.php';
require_once( $path.'Hybrid/Auth.php' );


This all seems to work in that it loads the library and throws a correct error. The next step would be to get some Application Keys - which I don't have - and add them to the config.php file to test I'm making a Connection*.

Bob

* I did see somewhere that Twitter may require an HTTPS connection to work correctly.
BNDragon 27 Oct, 2014
Hello everyone,

Well Max, I'm trying to replicate the examples, but it is complicated. Regarding plugins for 3rd party apps, unfortunately do not fit me, can not produce the effect I'm after.
Thanks anyway.

Bob, I got exactly the same result as you, but still unsolved, even using Application Keys, still the same result.

I tested (the sample) in localhost and facebook, google +, twitter and linkedin worked very well.

I'm trying to solve the problem but it is difficult. The result is always the same, the page saying that carried the Libraria php. :/

BN
GreyHead 27 Oct, 2014
Hi BN,

I'm not clear what worked and what failed ??

What error do you get exactly?

Bob
BNDragon 27 Oct, 2014
Hi Bob,

Thanks for your quick response.

I have a problem now, I wanted replicaro problem to give you exactly what happened, but now used the same steps (change the line of config.php "
"base_url" => JURI::root().'components/com_chronoforms5/extras/hybridauth/',
" and cared for custom action [first action to be handles the onLoad] event page the code here Simple Sign-In with Twitter example, changing the lines 5-7, as you said) it gives me a blank page with the address "http://mydomain.com/components/com_chronoforms5/extras/hybridauth/?hauth.start=Twitter&hauth.time=1414425983".

I'll try to fix, and replicate again what you told me and then explain better what happened.

BN
GreyHead 27 Oct, 2014
Hi BN,

Please try removing the last / from the url so the code is
"base_url" => JURI::root().'components/com_chronoforms5/extras/hybridauth',

Bob
BNDragon 27 Oct, 2014
Hi Bob,

Sorry, but now it gives me an access problem.

You cannot access this page directly.



I've re-upload the folder hybridauth but the result is the same.


This is the code of my Custom Action:
    <?php
    // start a new session (required for Hybridauth)
    session_start();
// change the following paths if necessary
$path = JPATH_SITE.'/components/com_chronoforms5/extras/hybridauth/';
$config   = $path.'config.php';
require_once( $path.'Hybrid/Auth.php' );
    try{
    // create an instance for Hybridauth with the configuration file path as parameter
    $hybridauth = new Hybrid_Auth( $config );
    // try to authenticate the user with twitter,
    // user will be redirected to Twitter for authentication,
    // if he already did, then Hybridauth will ignore this step and return an instance of the adapter
    $twitter = $hybridauth->authenticate( "Twitter" );
     
    // get the user profile
    $twitter_user_profile = $twitter->getUserProfile();
    echo "Ohai there! U are connected with: <b>{$twitter->id}</b><br />";
    echo "As: <b>{$twitter_user_profile->displayName}</b><br />";
    echo "And your provider user identifier is: <b>{$twitter_user_profile->identifier}</b><br />";
     
    // debug the user profile
    print_r( $twitter_user_profile );
     
    // exp of using the twitter social api: Returns settings for the authenticating user.
    $account_settings = $twitter->api()->get( 'account/settings.json' );
     
    // print recived settings
    echo "Your account settings on Twitter: " . print_r( $account_settings, true );
     
    // disconnect the user ONLY form twitter
    // this will not disconnect the user from others providers if any used nor from your application
    echo "Logging out..";
    $twitter->logout();
    }
    catch( Exception $e ){
    // Display the recived error,
    // to know more please refer to Exceptions handling section on the userguide
    switch( $e->getCode() ){
    case 0 : echo "Unspecified error."; break;
    case 1 : echo "Hybriauth configuration error."; break;
    case 2 : echo "Provider not properly configured."; break;
    case 3 : echo "Unknown or disabled provider."; break;
    case 4 : echo "Missing provider application credentials."; break;
    case 5 : echo "Authentification failed. "
    . "The user has canceled the authentication or the provider refused the connection.";
    break;
    case 6 : echo "User profile request failed. Most likely the user is not connected "
    . "to the provider and he should authenticate again.";
    $twitter->logout();
    break;
    case 7 : echo "User not connected to the provider.";
    $twitter->logout();
    break;
    case 8 : echo "Provider does not support this feature."; break;
    }
     
    // well, basically your should not display this to the end user, just give him a hint and move on..
    echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();
    }



I've tried to add
?>
at the end of the code, the same result.

The
/
at the end of the address of the
base_url
(add or remove it), reveals no change.

I did not realize what happened.

bN
BNDragon 28 Oct, 2014
Hello Bob,

Good and bad news.

The good news is that the address that appears is the callback from Twitter. What is on the one hand is excellent because after working.

The bad news is that I still problems with access, I'm trying to change the callbacks to see if I can get it to work, but still no success.

I'll give news;)
Many thanks for your help, I must say that without your guidelines would impossible for me to implement this.

BN
BNDragon 28 Oct, 2014
Hello Bob,

I think I'm about to get it, what is missing now is how to put the values โ€‹โ€‹into the form fields.

In other words, after logging in via twitter, keep everything in the variable
$userProfile


print_r($userProfile)

Hybrid_User_Profile Object
(
    [identifier] => XXXXXXXXXX
    [webSiteURL] => 
    [profileURL] => http://twitter.com/myUser
    [photoURL] => http://abs.twimg.com/sticky/default_profile_images/default_profile_0.png
    [displayName] => myUser
    [description] => 
    [firstName] => BNDragon
    [lastName] => 
    [gender] => 
    [language] => 
    [age] => 
    [birthDay] => 
    [birthMonth] => 
    [birthYear] => 
    [email] => 
    [emailVerified] => 
    [phone] => 
    [address] => 
    [country] => 
    [region] => 
    [city] => 
    [zip] => 
)


How do I associate, for example, the "username" field when given displayName?

BN
BNDragon 28 Oct, 2014
Upsi, I set it as solved, but it was an accident: /

Still need a little more help.
Max_admin 28 Oct, 2014
Something like this:
$form->data["field_name"] = $userProfile->displayName;

In a custom code action before the HTML action.
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 29 Oct, 2014
Hi Max,

It worked like a charm.

Last phase:
1 - other social networks (Facebook, Google Plus, Linkedin) (I think in principle I can do it myself, will only adapt the code from twitter, from what I noticed)
2 - The script loads automatically when you load the page, I want it to only load when you click on a button, how do I connect the php script to the button and then do the loading of data from the respective social network chosen? (Here I need your help)

For point number 2, I read something about the
call_user_func
function, there is no way not to use this?
Because the url can be changed by the provider, such as
?hauth.start=Twitter&hauth.time=1414425983
and I'm afraid that will not work.


I think it is "just" that.
After everything completed, so that I have a little time to spare, I will make a toturial to help others like me;)

Now and again, a big thank you, Max and Bob, you are a precious help.

BN
BNDragon 29 Oct, 2014
Hello there,

New question, the social network data return a link to the image
[photoURL] => http://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png


Use only the image link does not work for me, I need to save the image. So:

How can I do to save the image on my server?

And then how do I know the name of the image and then save it in the database?

thanks,
BN
BNDragon 29 Oct, 2014
Hello again,

Max, I'm trying to use the
call_user_func
function that is working, however there appeared a strange problem, now the code
$form->data["field_name"] = $userProfile->displayName;
does not work to fill out the form.

Do you can help me?
This is the code I am using the custom action
<?php
	if(isset($_GET['runFunction']) && function_exists($_GET['runFunction']))
	{
call_user_func($_GET['runFunction']);

	}
	function loginTwitterHA() {
		$path = JPATH_SITE.'/components/com_chronoforms5/extras/hybridauth/';
		$config   = $path.'config.php';
		require_once( $path.'Hybrid/Auth.php' );
		if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
			require_once( $path."Hybrid/Endpoint.php" );
			Hybrid_Endpoint::process();
			return;
		}
		$config = array(
			"base_url" => 'http://mydomain.com/entrar',
			"providers" => array(
			"Twitter" => array(
				"enabled" => true,
				"keys" => array("key" => "XXXXXXXXXXXXXXXXXXXXXXXXXXX", "secret" => "XXXXXXXXXXXXXXXXXXXXXXXXXXX"),
				)
			)
		);
		if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
			require_once( $path."Hybrid/Endpoint.php" );
			Hybrid_Endpoint::process();
			return;
		}
		try{
			$hybridauth = new Hybrid_Auth( $config );
			$twitter = $hybridauth->authenticate( "Twitter" ); 
			$userProfile = $twitter->getUserProfile();
			echo "<pre>";
			print_r( $userProfile );
			echo "</pre>";
			// $twitter->logout();
		
$form->data["nome"] = $userProfile->firstName;
$form->data["username"] = $userProfile->displayName;
$form->data["email"] = $userProfile->email;
		}
		catch( Exception $e ){
			switch( $e->getCode() ){
				case 0 : echo $e->getCode()." Unspecified error."; break;
				case 1 : echo $e->getCode()." Hybriauth configuration error."; break;
				case 2 : echo $e->getCode()." Provider not properly configured."; break;
				case 3 : echo $e->getCode()." Unknown or disabled provider."; break;
				case 4 : echo $e->getCode()." Missing provider application credentials."; break;
				case 5 : echo $e->getCode()." Authentification failed. "
				. "The user has canceled the authentication or the provider refused the connection.";
				break;
				case 6 : echo $e->getCode()." User profile request failed. Most likely the user is not connected "
				. "to the provider and he should authenticate again.";
				$twitter->logout();
				break;
				case 7 : echo $e->getCode()." User not connected to the provider.";
				$twitter->logout();
				break;
				case 8 : echo $e->getCode()." Provider does not support this feature."; break;
			}
			// well, basically your should not display this to the end user, just give him a hint and move on..
			echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();
		}
	}
?>



Thanks in advance,
BN
BNDragon 30 Oct, 2014
Hi there,

Sorry to bother again, but still no help?

Help me out in those last threads please

Thank you,
BN
Max_admin 30 Oct, 2014
Hi BN,

Does the print_r( $userProfile ); work ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 30 Oct, 2014
Hi MAx,

Yes, I can use
print_r( $userProfile );
but when try to use
$form->data["field_name"] = $userProfile->displayName;
it don't work.

BN
Max_admin 31 Oct, 2014
What do you get from the print_r ? do you get the object data as before ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 31 Oct, 2014
Hi Max,

Yes, I get the same object. Here an example (This is the Linkedin data)


Hybrid_User_Profile Object
(
    [identifier] => 999999999999999
    [webSiteURL] => 
    [profileURL] => https://www.linkedin.com/in/brunoneves90
    [photoURL] => https://media.licdn.com/mpr/mprx/xxxxxxxxxxxxxxxxxxxxxxxxx
    [displayName] => Bruno Neves
    [description] => Chamo-me Bruno, acabo de me licenciar em Tecnologias de Sistemas de Informaรงรฃo. Pretendo assumir como primeiro primeiro emprego analista de negรณcio e posteriormente chegar a gestor de projeto. Sou responsavรฉl, determinado, gosto de trabalhar por objetivos e faรงo parte da soluรงรฃo nรฃo do problema.
    [firstName] => Bruno
    [lastName] => Neves
    [gender] => 
    [language] => 
    [age] => 
    [birthDay] => 
    [birthMonth] => 
    [birthYear] => 
    [email] => bbbbb@gmail.com
    [emailVerified] => nnnnn@gmail.com
    [phone] => 
    [address] => 
    [country] => 
    [region] => 
    [city] => 
    [zip] => 
)


BN
Max_admin 31 Oct, 2014
Then it should work in the code, how do you know that it doesn't work ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 31 Oct, 2014
Hi Max,

I know that it doesn't work because the field remains empty. :? ๐Ÿ˜Ÿ

BN
BNDragon 31 Oct, 2014
Max, please note that only happen inside the funcion, if I remove the function and put only the code it works. The problem is when it is in the function.
Max_admin 31 Oct, 2014
Ok, maybe because the $form variable doesn't exist inside the function, you may have to pass it by reference:
function(&$form, ...other params)
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 03 Nov, 2014
Hi Max,

It worked very well ^^

But, relatively to the other question?
How can I import pictures from social networks?
Hi receive from social networks, something like this
[photoURL] => http://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png


I made a little hack to the database and pasted the link there that is returned, which results in no image displayed.

I believe this is my last question on this subject.
Many thanks for all the help,
BN
GreyHead 03 Nov, 2014
Hi BN,

Does that URL show an image if you paste it into your browser?

If so then is should display if you put it in an <img> tag.

Bob
BNDragon 03 Nov, 2014
Hi Bob,

Yes it shows, but Comunnity Builder use relative path, if i give a link, it don't work. And I prefer don't hack CB core files.

I try to use the php function
copy
, but it gives a

Forbidden

You don't have permission to access /administrator/index.php on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request



When I save the form in the backend, it don't let me save the form with the
copy 
function on it :/

BN
BNDragon 03 Nov, 2014
Ok, I think I found the problem, i try to use this three codes:
copy($userProfile->photoURL, JPATH_SITE.'/images/comprofiler/'.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).''.image_type_to_extension($userProfile->photoURL));


if(!@copy($userProfile->photoURL, JPATH_SITE.'/images/comprofiler/'.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).''.image_type_to_extension($userProfile->photoURL));)
{
    $errors= error_get_last();
    echo "COPY ERROR: ".$errors['type'];
    echo "<br />\n".$errors['message'];
} else {
    echo "File copied from remote!";
}


// The JPG image you want to copy from someone else's website ... 
$filename = $userProfile->photoURL; 

// Re-create it by using GD ... 
$image = imagecreatefromjpeg($filename); 

if(image_type_to_extension($userProfile->photoURL)==".jpg" || image_type_to_extension($userProfile->photoURL)==".jpeg")
{
$time=time();
imagejpeg($image, JPATH_SITE.'/images/comprofiler/'.$time.''.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).'.jpg',100); 
// Free up memory 
imagedestroy($image); 


What they have in common? Basically store an image on my server. I think for some reason I ignore, I'm not allowed to write code to do it. ๐Ÿ˜Ÿ

BN
BNDragon 03 Nov, 2014
I reviewed the latest code, and in fact it would not work, so I rewrote it, but the same result :? ๐Ÿ˜Ÿ


// The JPG image you want to copy from someone else's website ... 
$filename = $userProfile->photoURL; 

// Re-create it by using GD ... 

if(image_type_to_extension($userProfile->photoURL)==".jpg" || image_type_to_extension($userProfile->photoURL)==".jpeg")
{
$image = imagecreatefromjpeg($filename); 
$time=time();
imagejpeg($image, JPATH_SITE.'/images/comprofiler/'.$time.''.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).'.jpg',100); 
// Free up memory 
imagedestroy($image); 

echo "saved ... <a href='".JPATH_SITE."/images/comprofiler/".$time."".preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).".jpg'>view it now</a>"; 
} elseif (image_type_to_extension($userProfile->photoURL)==".png")
{
$image = imagecreatefrompng($filename); 
$time=time();
imagepng($image, JPATH_SITE.'/images/comprofiler/'.$time.''.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).'.jpg',100); 
// Free up memory 
imagedestroy($image); 

echo "saved ... <a href='".JPATH_SITE."/images/comprofiler/".$time."".preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).".png'>view it now</a>"; 
} elseif (image_type_to_extension($userProfile->photoURL)==".gif")
{
$image = imagecreatefromgif($filename); 
$time=time();
imagegif($image, JPATH_SITE.'/images/comprofiler/'.$time.''.preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).'.gif',100); 
// Free up memory 
imagedestroy($image); 

echo "saved ... <a href='".JPATH_SITE."/images/comprofiler/".$time."".preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName).".gif'>view it now</a>"; 
} else echo "Image type not supported.";



BN
Max_admin 03 Nov, 2014
You have an image url, so you either use it in an img tag "as its", because the image is not on your website, or you can read the url data (the image) and save it to your website first under the CB images path, just google how to read img url and save it in PHP, you can do this with file_get_contents function I think!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 03 Nov, 2014
Hi BN,

Is it possible that FaceBook etc. have code in place to stop the copying of images ???

Bob
BNDragon 03 Nov, 2014
Hi Max and Bob,

Already responding to Bob, I can not answer that for now.

I tried using your suggestion Max, but the result remains the same access problem, I can not change the code to create files on the server.

Well, I guess not explained myself well, the issue is not saving the form in the frontend, the problem is in the backend whenever I insert the code to create a file on the server, just gives me an access problem (which I mentioned the three posts above).

BN
BNDragon 03 Nov, 2014
Ok, I tried to put the bug report of Joomla maximum, and the site just crashed, neither by ftp could access the files, and i decided by CPanel and I managed to change the configuration file to leave everything as it was.

And then I remembered: "Why the hell did I have not yet see the error log here?"

And it was where I saw an error in the least curious:
[Mon Nov 03 15:51:14 2014] [error] 
[client XX.XXX.XXX.XX] 
File does not exist: /home/domainUser/public_html/403.shtml, 
referer: http://domain.com/sub/domain/administrator/index.php?option=com_chronoforms5&act=edit&id=20

What makes no sense since it is the form I'm trying to change, and that if I did not put the code to save the images, the form is saved without any problem.

Idea what can be?
BN
Max_admin 03 Nov, 2014
Where do you save the code in your form ?

Some security modules on the server may block saving specific patterns of PHP code, maybe this is the source of the issue here.
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 03 Nov, 2014
I set it in a Custom Action, and it is the first Action onLoad.

How can I know if it is the problem of the security modles?

BN
BNDragon 03 Nov, 2014
I'm starting to get nutcase !!!!๐Ÿ˜ˆ

Now, I can not use the
preg_replace
function!
Gives permission error when saving the form, I removed the line that contained the function and have kept all right!

I really do not know what to do v.v
Max_admin 03 Nov, 2014
I think this is a security module, you can ask your host admin, there is nothing you can do from your end, and Chronoforms doesn't try to run the code when you save the form!

Alternatively you can put all your code into a file and just include it in your custom code action, that would not trigger the security restrictions!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 10 Nov, 2014
Hello Max,

Sorry to be no news, but another project came up and I had to for this on stand by until the new finish.

I imported the php file and it worked after a few tries and a morning of research, I finally managed to save the image. The function that you suggest (file_get_contents) was returning a string full of special characters, while searching I saw a method of saving the image, using the same function, and for some reason, it worked well.
$filename = file_get_contents('https://graph.facebook.com/'.$userProfile->identifier.'/picture?type=large');
$file = JPATH_ROOT.'/images/comprofiler/'.$time.''.strtolower(preg_replace("/[^a-zA-Z]+/", "", $userProfile->displayName)).'.png';
file_put_contents($file, $filename);


My problem is now on the user, explaining better:

I'm doing tests with my personal account, but now I decided to try another account, I created an account for testing on FB, and gives the following error:
Warning
Application not configured: The developers of this application is not configured properly for this application Login Facebook.


After some research, I found that it was due to my application not be public, currently already works perfectly in this aspect, but there's one snag. There is always a but v.v

I always clean the cache to read a new user.
I saw this code here:
$ cache = JFactory :: GetCache ('com_chronoforms');
$ cache-> clean ();

But it did not work: /

Can you help?

BN
BNDragon 11 Nov, 2014
Hi there,

Can't you give some help?
BN
Max_admin 12 Nov, 2014
Hi BN,

Chronoforms doesn't cache anything, except the database table info which can be deleted only using the "Delete cache" button in the Chronoforms admin area.

I'm really not sure what to tell about the problem you have, its a pure FB connection issue, which I don't have any experience with.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 13 Nov, 2014
Hi Max,

Thanks for your reply,

You point me up a good point. And I think you're half right. I did some more tests, and I realized that in fact the HybridAuth save the data, so it's not quite the connection itself.

What is happening, so it is realized that the command
$fb>logout()
is not working. (I think.)

I'll try to fix it somehow.

BN
BNDragon 13 Nov, 2014
Hi Max,

I found what is wrong. The HybridAuth save cookies,

So, i'm tryng to delete that cookies. I'm using this code

// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
    $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
    foreach($cookies as $cookie) {
        $parts = explode('=', $cookie);
        $name = trim($parts[0]);
        setcookie($name, NULL, time()-1000);
        setcookie($name, NULL, time()-1000, '/');
    }
}


The problem is: if I use it at the top of my custom Action, the form won't load, if I use it inside the function, it won't work v.v

I saw all the actions of CF5, and saw nothing about this, so I assume that there is no control of cookies, right?

BN
GreyHead 13 Nov, 2014
Hi BN,

ChronoForms doesn't use Cookies and has no special code for handling them. You don't say where you have your code but it does need to be in <?php ?> tags and probably should only clear the specific cookies that HybridAuth is setting rather than all of them.

Bob
BNDragon 13 Nov, 2014
Hi Bob,

You right, but the problem is that I don't know the name of the cookies :/

I had already set the code inside php tags.

Sorry for late reply, now, besides having this problem with the cockies, I still have another with AceSEF.
I'm giving in nutcase this week. v.v

BN
Max_admin 13 Nov, 2014
Hi BN,

By the "form will not load" you mean that you get a blank page ? if yes then please set the error reporting to maximum to get the error.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 17 Nov, 2014
Hi Max,

It almost a blanck page, It print the data from the Social Network, but Bob is right, clean all cookies is not a good way to do it.
So I need to prevent creat cookies from HybridAuth or clean cookies created from it, the problem now is that I don't know wicth one is created. ๐Ÿ˜Ÿ

Rgds,
BN
Max_admin 17 Nov, 2014
Hi BN,

Then just try to find a setting in the library to disable the cookies or edit the code to comment this part!๐Ÿ™‚

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 19 Nov, 2014
1 Likes
Hi Max,

Finally resolved problems with SEF (I think) and managed to resume the form.

I managed to make "work".

I set this code in a Javascript Load action
jQuery(function ()
{
var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
    	var cookie = cookies[i];
    	var eqPos = cookie.indexOf("=");
    	var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
    	document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
});


What works when the user enter the page but not when it returns from the social network.
Ie, when you click the menu button to the form and then a button to social login (Facebook, for example) reads data directly from facebook, but if you click the same button again HybridAuth reads data from cache/cookies :/

BN
Max_admin 21 Nov, 2014
Then try to put this code inside a js function and call it on document ready event + on facebook button click event!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 21 Nov, 2014
Hi Max,

But if it is the first action of the onLoad event it should work every time the page is load right?

BN
Max_admin 23 Nov, 2014
Not necessarily, the code will be loaded every time, but if the code is not attached to the document ready event or the button click event then it will run only when its loaded on the page!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 24 Nov, 2014
Hi Max,

Thats true, nut I set it in on a ready event:
jQuery(function ()
{
var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
    	var cookie = cookies[i];
    	var eqPos = cookie.indexOf("=");
    	var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
    	document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
});


The other possibility is put it in my js custom file and in CF call the function, but I thought that it will always work as it is.
I'm no pro in js, but in my searches to learn it, I believe that is how it should work :/

BN
GreyHead 24 Nov, 2014
Hi BN,

Please try
jQuery(document).ready(function () {
. . .
});
or I prefer
jQuery(document).ready(function (jQ) {
. . . 
});
which lets me replace $ with jQ so I am reminded which library I'm using.

Bob
BNDragon 24 Nov, 2014
Hi Bob,

Thanks for your suggestion, but the result is the same, it will work for now.

One question, I know that is not relative to CF, but, how do I do a Joomla Login?
I start to put the code in the final form, and I realize that I don't know how to make the user login if he is already registed.
Can you help me in this?
Or indicate me how do I make a php code to activate the joomla login action.

Really thanks,
BN
Max_admin 25 Nov, 2014
Hi BN,

The code is available in the Joomla login action in Chronoforms, but you need a valid Joomla username and password, and here you use FB credentials, so I'm not sure if this will work, without an authentication system plugin!

However, I don't have experience with this!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 25 Nov, 2014
Hi Max,

Thanks for your reply,

I can set the password in the table of HybridAuth, but it would be a security issue :/

I'll search/create a encrypt/decrypt system to remove the security issue, then I probably can use this solution.

Thanks Max,
BN
Max_admin 25 Nov, 2014
You can check the Joomla authenticate plugins, for example there is one for GMail, that should be an easier approach!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 25 Nov, 2014
Hi Max,

I found a script:
<?php
define("ENCRYPTION_KEY", "keyEncript");
$string = "This is the original data string!";

echo $encrypted = encrypt($string, ENCRYPTION_KEY);
echo "<br />";
echo $decrypted = decrypt($encrypted, ENCRYPTION_KEY);

/**
 * Returns an encrypted & utf8-encoded
 */
function encrypt($pure_string, $encryption_key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
    return $encrypted_string;
}

/**
 * Returns decrypted original string
 */
function decrypt($encrypted_string, $encryption_key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv);
    return $decrypted_string;
}
?>


I'm testing it, and it may be the solution, if i calculate the key, then I can make it work, tomorrow I'll finish tests and say if it works.

Really thanks for help me out,
bN
Max_admin 25 Nov, 2014
And what's this supposed to do ? Joomla uses specific method to encrypt the passwords, and they can't be decrypted!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
BNDragon 26 Nov, 2014
Is supposed to encrypt/decrypt the original password.

I was think do some like this:

To save in database:
 $password = encrypt($form->data["password"], ENCRYPTION_KEY);


Then, when the user login with a Social Network, I get the proveider_uid, then do something like:
$q=mysqli_query($con,"Select username, password From myAuthTable where p_id=".$userProfile->identifier.");
$line = mysqli_fetch_array($q);  
$username=$line['username'];
$password=decrypt($line['password '], ENCRYPTION_KEY);


And here enter the login function, that is hard to me integrate, but it will be something like:
$config = new \GCore\Libs\Parameter($config);
		
		$mainframe = \JFactory::getApplication();

		$credentials = array();
		$credentials['username'] = $username;
		$credentials['password'] = $password;
		if($mainframe->login($credentials) === true){
			$this->events['success'] = 1;
		}else{
			$this->events['fail'] = 1;
			$form->errors[] = 'Invalid username or password.';
			return false;
		}


I didn't test it already, but will soon, try to solve other bug (open new topic next), and the logic is good, the problem is that the login code probably don't work.

BN
BNDragon 26 Nov, 2014
Hi there,

I found a big problem my friends, I use the url to call the function of the social network, so my url is some like
mydomain.com?runFunction=loginTwitterHA

This is working, but the problem is when I submit the form, what happen is that the CF add his vars to url without clean it, so it is some like
mydomain.com?runFunction=loginTwitterHA&chronoform=RegistoFinal&event=submit


How do I remove the
runFunction=loginTwitterHA
when I submit the form?

BN
BNDragon 27 Nov, 2014
Hi,

In a new fresh morning I got and idea to solve the last problem, heres the tip if someone else use var in url, just test if there are others vars, in my case it becomes some like:
if(isset($_GET['runFunction']) && function_exists($_GET['runFunction']) && !isset($_GET['event']))
	{
		call_user_func($_GET['runFunction'],$form);
	}	


Now, finally time to test register/login with social networks๐Ÿ˜€

BN
BNDragon 05 Jan, 2015
Hi there,

Finally come an idea to solve the login prob, I couldn't figure it out how to use joomla login, so I used CF login form.

When The user login by (ie) fb, if he already is resisted then simpled add the data from DB to the form

		
		$user = $linha['loginName'];
		$pass = decrypt($linha['loginPass'],$userProfile->identifier);
		
		$form->data["loginUsername"] = $user;
		$form->data["loginPass"] = $pass;


Then I created a in-line jquery ready function by a echo to click the login button
echo "<script type='text/javascript'>
		jQuery(function ()
			{
				jQuery('#bLogin').click();
			});
			</script>";


Now it looks kind of easy. v.v

To all you that help me out to make this form, my big big thanks.
I passed my code to deef73, he's trying to make it work too, so, sooner or later probably I or he will post some tutorial to all that want this kind of form.

Once again, my thanks, special to you two Bob and Max,

BN
This topic is locked and no more replies can be posted.