2017 © Pedro Peláez
 

library social-login

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

image

venca-x/social-login

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  • Wednesday, June 13, 2018
  • by venca-x
  • Repository
  • 1 Watchers
  • 3 Stars
  • 408 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 11 Versions
  • 23 % Grown

The README.md

social-login

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Nette addon for login with social networks, (*2)

Version Facebook App API PHP Recommended Nette
dev-master 8.0 or own >= 7.2 (support 8.0) Nette 3.0
1.2.x 8.0 or own >= 7.2 (support 8.0) Nette 3.0
1.1.x 2.6 >= 7.0 Nette 2.4 (Nette\SmartObject)
1.0.x 2.6 >= 5.5 Nette 2.4, 2.3 (Nette\Object)

All permissions for Facebook fields, (*3)

Installation

Install dev-master version for Nette 3.0:, (*4)

composer require venca-x/social-login:dev-master

Install 1.2.x version for Nette 3.0 (Nette\SmartObject):, (*5)

composer require venca-x/social-login:^1.2.0

Install 1.1.x version for Nette 2.4 (Nette\SmartObject):, (*6)

composer require venca-x/social-login:^1.1.0

Install 1.0.x version for Nette 2.4 or Nette 2.3 (Nette\Object):, (*7)

composer require venca-x/social-login:^1.0.0

Configuration

config.neon, (*8)

    parameters:
        facebook:
            appId: '123456789'
            appSecret: '987654321'
            callbackURL: 'http://www.muj-web.cz/homepage/facebook-login'
            defaultFbGraphVersion: 'v8.0'
        google:
            clientId: '123456789'
            clientSecret: '987654321'
            callbackURL: 'http://www.muj-web.cz/homepage/google-login'
        twitter:
            consumerKey: '123456789'
            consumerSecret: '987654321'
            callbackURL: 'http://www.muj-web.cz/homepage/twitter-login'

    nette:
        session:
            autoStart: true  # default is smart 

    services:
        ...
        - VencaX\SocialLogin({ facebook: %facebook%, google: %google%, twitter: %twitter% }, 'domain-social-login' )

Where 'domain-social-login' replace to your unique identifier (it's cookie name for last used services for login), (*9)

BasePresenter.php, (*10)

    use VencaX;

    /** @var VencaX\SocialLogin */
    private $socialLogin;

    public function injectSocialLogin( VencaX\SocialLogin $socialLogin )
    {
        $this->socialLogin = $socialLogin;

        //set scope
        $this->socialLogin->facebook->setScope( ['email'] );
        $this->socialLogin->google->setScope( array( "https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/userinfo.email" ) );       
    }

    public function renderIn() {
        //$facebookLoginUrl = $this->socialLogin->facebook->getLoginUrl();
        //$googleLoginUrl = $this->socialLogin->google->getLoginUrl();
        //$twitterLoginUrl = $this->socialLogin->twitter->getLoginUrl();

        //dump( $this->socialLogin->getSocialLoginCookie() );

        //$this->template->facebookLastLogin = $this->socialLogin->facebook->isThisServiceLastLogin();
        //$this->template->googleLastLogin = $this->socialLogin->google->isThisServiceLastLogin();
        //$this->template->twitterLastLogin = $this->socialLogin->twitter->isThisServiceLastLogin();
        //...
    }

Layout for in.latte:, (*11)

    <a rel="nofollow" href="{$facebookLoginUrl}" {if $facebookLastLogin}class="last-login"{/if}><i class="fa fa-facebook-square fa-lg"></i></a>
    <a rel="nofollow" href="{$googleLoginUrl}" {if $googleLastLogin}class="last-login"{/if}><i class="fa fa-google-plus-square fa-lg"></i></a><br/>
    <a rel="nofollow" href="{plink User:twitterLogin}" {if $twitterLastLogin}class="last-login"{/if}><i class="fa fa-twitter-square fa-lg"></i></a><br/>
    <a rel="nofollow" href="{plink User:registration}"><i class="fa fa-plus-square fa-lg"></i> Zaregistrovat</a>

Simple login

HomepagePresenter.php, (*12)

    public function actionFacebookLogin()
    {
        try
        {
            $me = $this->socialLogin->facebook->getMe( array( FacebookLogin::ID, FacebookLogin::EMAIL, FacebookLogin::NAME, FacebookLogin::FIRST_NAME, FacebookLogin::LAST_NAME ) );
            dump( $me );
            exit;
        }
        catch( Exception $e )
        {
            $this->flashMessage( $e->getMessage(), "alert-danger" );
            $this->redirect("Homepage:default");
        }
    }

    public function actionGoogleLogin( $code )
    {
        try
        {
            $me = $this->socialLogin->google->getMe( $code );
            dump( $me );
            exit;
        }
        catch( Exception $e )
        {
            $this->flashMessage( $e->getMessage(), "alert-danger" );
            $this->redirect("Homepage:default");
        }
    }
    //...

Simple logint with Twitter

    public function actionTwitterLogin($oauth_token, $oauth_verifier)
    {
        try {
            $me = $this->socialLogin->twitter->getMe($oauth_token, $oauth_verifier);
            //$me = $this->socialLogin->twitter->getMe($oauth_token, $oauth_verifier, true);//when zou want user's email
            dump($me);
            exit;
        } catch (Exception $e) {
            $this->flashMessage($e->getMessage(), 'alert-danger');
            $this->redirect('Homepage:default');
        }
    }

Use it when you want to redirect to specific URL after success login, (*13)

HomepagePresenter.php, (*14)

    private $backlink = null;

    //render where are links to social networks  
    public function renderIn() {
        if ($this->backlink) {
            $this->socialLogin->facebook->setState($this->backlink);
            $this->socialLogin->google->setState($this->backlink);
        }

        //$facebookLoginUrl = $this->socialLogin->facebook->getLoginUrl();
        //$googleLoginUrl = $this->socialLogin->google->getLoginUrl();
        //$twitterLoginUrl = $this->socialLogin->twitter->getLoginUrl();

        //dump( $this->socialLogin->getSocialLoginCookie() );

        //$this->template->facebookLastLogin = $this->socialLogin->facebook->isThisServiceLastLogin();
        //$this->template->googleLastLogin = $this->socialLogin->google->isThisServiceLastLogin();
        //$this->template->twitterLastLogin = $this->socialLogin->twitter->isThisServiceLastLogin();
    }

    public function actionFacebookLogin($state = NULL)
    {
        try
        {
            if ($state) $this->backlink = $state;
            $me = $this->socialLogin->facebook->getMe();
            //dump( $me );
            //exit();
            if($this->backlink != null) {
                $this->redirect($this->backlink);
            }
        }
        catch( Exception $e )
        {
            $this->flashMessage( $e->getMessage(), "alert-danger" );
            $this->redirect("Homepage:default");
        }
    }

    public function actionGoogleLogin( $code, $state = NULL )
    {
        try
        {
            if ($state) $this->backlink = $state;
            $me = $this->socialLogin->google->getMe( $code );
            //dump( $me );
            //exit();
            if($this->backlink != null) {
                $this->redirect($this->backlink);
            }
        }
        catch( Exception $e )
        {
            $this->flashMessage( $e->getMessage(), "alert-danger" );
            $this->redirect("Homepage:default");
        }
    }
    ...

Registration

Facebook

Facebook Developers - create new website app. Full: Settings -> Web page -> Site URL : http://www.mypage.com, (*15)

Google

API Console - Google Code - create new project add Google+ API: APIs & auth -> APIs -> Google+ API set ON credentials: APIs & auth -> Credentials -> Crate new Client ID -> Web application, (*16)

Twitter

Register a new app at dev.twitter.com/apps/, (*17)

The Versions

13/06 2018

dev-master

9999999-dev

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

The Development Requires

php nette social login facebook login google login twitter login

13/06 2018

v1.1.x-dev

1.1.9999999.9999999-dev

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

13/06 2018

1.1.1

1.1.1.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

07/05 2018

1.1.0

1.1.0.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

30/12 2017

v1.0.x-dev

1.0.9999999.9999999-dev

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

30/12 2017

v1.0.7

1.0.7.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

03/12 2017

1.0.6

1.0.6.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

24/08 2017

v1.0.5

1.0.5.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

24/08 2017

v1.0.4

1.0.4.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

04/05 2016

1.0.0

1.0.0.0

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login

27/12 2014

v1.0-beta

1.0.0.0-beta

Nette addon. Login with social networks ( Faceboook, Google, Twitter )

  Sources   Download

MIT

The Requires

 

php nette social login facebook login google login twitter login