Jump to content

Social Login


baba_mmx

Recommended Posts

Hi,

first of all I'd like to thank you all, and in particular Ryan, for this great project which is ProcessWire.

I'm using ProcessWire for the first time and frankly I'm finding it quite good, despite my lack of experience.

Anyway, I created this post to introduce you the following module, on which we are working, and I'd like to share it with the community which could benefit from it and maybe improve it.

You can find the module here: https://bitbucket.org/mauro_mascia/processwire-social-login/

Basically, it adds the ability to allow a social login (using the HybridAuth library - https://github.com/hybridauth/hybridauth) as well as a standard login, user profile and registration.
 
The module is clearly not complete and it is at its first stage of maturity and I hope you can forgive me if I have not fully complied with the PW best practices :)
Edited by LostKobrakai
Moved to modules forum and updated tags to be appropriate for the subforum
  • Like 19
Link to comment
Share on other sites

Very nice start!

I saw this and before I go on with viewing the module and forget to tell you, you need to specify the version number as integer: 1 or as string "0.0.1". Using 001 will lead in complications with modules upgrades, modules manager etc.

Link to comment
Share on other sites

Thanks dudes.

I've fixed the version number.

Now a couple of informations: in the providers config file can be specified all providers supported by HybridAuth. For now we have enabled and tested just Facebook and Twitter, and enabled Google but not tested yet (but if it works for "i" and i+1 it should work also for i+N).

Each provider will be shown as collapsed fieldset, if not enabled, to save space. 

Attached, there is a picture of this.

This configuration file is used for:

  • create the module edit section (as shown in the above picture)
  • show enabled providers in the login form (see)
  • retrieve info to be processed when the user is doing a login with a certain provider (see)

Naturally more providers can be added, following the structure of the returned array.

post-3300-0-26455000-1429353627_thumb.pn

  • Like 2
Link to comment
Share on other sites

hi baba_mmx,

very cool! cstevensjr was faster with the images: https://processwire.com/talk/topic/8597-best-way-to-get-random-quote-displayed-on-refresh/?p=83195

is it a good idea to post your app id and secret? don't know how they are used and if anybody can misuse them?

your version number is still 002 and not 2

'version' => 2,

don't know what could be the problems but i'm trusting horst and the ryan's helloworld module :)

Link to comment
Share on other sites

your version number is still 002 and not 2

'version' => 2,

don't know what could be the problems but i'm trusting horst and the ryan's helloworld module :)

Numbers preceded by a 0 are parsed by php as octal numbers (base 8). 

var_dump(013); // outputs int(11), because it's 1*8 + 3
  • Like 1
Link to comment
Share on other sites

Added registration with confirmation email and activation link  ^-^

I've mainly followed this thread https://processwire.com/talk/topic/4066-activate-user-account-via-email/

The user who registers is created with the unpublished status:

$new_user->addStatus( Page::statusUnpublished );

and when she/he clicks on the confirmation link received via email the status turns published:

            $activate_userid = $this->sanitizer->text( $this->input->get->userid );
            $activate_hash = $this->sanitizer->text( $this->input->get->hash );
            $this_user = $this->wire('pages')->find( "template=user,id=$activate_userid, include=all" )->first();

            if ( is_object( $this_user ) && isset( $this_user->id ) ) {
                if ( strcmp( $this_user->activation_key, $activate_hash ) == 0 && $this_user->is( Page::statusUnpublished ) ) {
                    echo __( "Thank you! Your account has been activated!" );

                    $activate_user = $this_user;
                    $activate_user->of(false);
                    $activate_user->activation_key = "0";
                    $activate_user->removeStatus( Page::statusUnpublished );
                    $activate_user->save();
                }
            }

In the attached pic the configuration page which allows to specify email's fields.

As a side note, I've initially tried to get the user with his username:
 
$this->wire( 'users' )->find( "name=$activate_username, include=unpublished" );
but the returned object was really complex and completely protected, so I've changed the behaviour using the user's id.

post-3300-0-81548400-1429607469_thumb.pn

  • Like 4
Link to comment
Share on other sites

  • 2 months later...

I keep meaning to comment on this topic as it's something that interests me but I've been so busy lately (and not fun busy unfortunately).

I've been looking to do something like this for a while so thanks for saving me some effort :)

Just a few thoughts on future functionality - I know the forums here allow Twitter and Facebook logins and you can link both to a normal account too (I have my Twitter and FB linked to this account). It gets a bit tricky, but it would make sense at some point if you can associate other provider logins with the same PW account. The easiest check I guess would be if the email address stored for the provider account already matched a PW account on the site, so after authenticating at Google for example, it things "well there's an account here already with the same address - let's ask the user if they want to link them rather than create a new profile and ask them for their existing account's password to continue".

I know, it's not exactly straightforward and it's more work, but if you get all your accounts linked together nicely you can then start thinking about other functionality like pushing updates to all of those providers through your PW site. Fun stuff!

Link to comment
Share on other sites

  • 3 months later...
  • 4 months later...
  • 2 weeks later...

Who can help please?
This is the problem that I have with Processwire 3.12 and the module SocialLogin...


this line does not work! (Error: Class 'ProcessProfile' not found )

class SocialLoginProcessProfile extends ProcessProfile {

does it has to do with the new namespace thing in processwire 3.x?

<?php namespace ProcessWire;

/**
 * ProcessWire Self Profile
 *
 * ProcessWire 3.x (development), Copyright 2015 by Ryan Cramer
 * https://processwire.com
 *
 * 
 * @property array $profileFields Names of fields user is allowed to edit in their profile
 *
 */

class ProcessProfile extends Process implements ConfigurableModule, WirePageEditor {

	public static function getModuleInfo() {
		return array(
			'title' => __('User Profile', __FILE__), // getModuleInfo title          
			'summary' => __('Enables user to change their password, email address and other settings that you define.', __FILE__), // getModuleInfo summary 
			'version' => 101, 
			'permanent' => true, 
			'permission' => 'profile-edit',
			);
	}

Link to comment
Share on other sites

That would be so nice from you!

You other guys could try if it works for you, if you comment out these lines in the code!
For me this error is gone... (of course you cannot show your profile...)

    public function showProfile() {
   //     require_once( "classes/SocialLoginProcessProfile.php" );

   //     $SocialLoginProcessProfile = new SocialLoginProcessProfile( $this->enabled_profile_user_fields );
   //     $SocialLoginProcessProfile->process();
    }

but I have now a google uri mismatch error..
google told me this uri is wrong:
http://terminio.at//en/social-login/?hybridauth=login&hauth.done=Google

but I added it at my google credentials...
I don´t understand why this can be wrong...

Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...
On 12.3.2016 at 6:56 PM, baba_mmx said:

Unfortunately at the moment I'm unable to work on this. Maybe someone in the forum can take it under his wing?

Been there done that.

I proudly present a ProcessWire 3 compatible version with the latest HybridAuth (only tested with Facebook).

The code can be found on Github https://github.com/jmartsch/processwire-social-login with installation instructions.

Please add your suggestions or create pull requests.

The module and its dependencies are installed via composer.

Have phun!

  • Like 9
Link to comment
Share on other sites

  • 2 weeks later...

Hey guys, hey @baba_mmx I just released a new version of this module on github. I also got a question, as I am planning to take this project under my wing: Should I make a new thread for it and add it to the modules directory? @baba_mmx would that be ok with you?

One problem is that if I put it in the ProcessWire Modules directory it does not install it dependencies, as they are installed via composer. How could I handle this?

What has been done in the latest release?

v0.9.1

made the register form public so you can alter the markup and classes
added Foundation classes for the errors and notices. Have to make this configurable
added new function showMessage to echo messages and errors
login user after successful registration
removed automatic redirect
enabled autocompletion for the form
show either displayName from OAuth or email address after login
added the ability to save the last name, first name and gender from OAuth in the user profile. Just add the fields "lastName", "firstName" and "gender" to the user template in ProcessWire

  • Like 4
Link to comment
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
×
×
  • Create New...