GithubHelp home page GithubHelp logo

neuralnoise / social-login Goto Github PK

View Code? Open in Web Editor NEW

This project forked from venca-x/social-login

0.0 2.0 0.0 35 KB

Plugin for Nette. Login with social networks (Facebook, Google, Twitter )

PHP 100.00%

social-login's Introduction

social-login

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Nette addon for logint with social networks

Version 1.0.0 use Facebook App API version v 2.6 All permissions for Facebook fields

Installation

Add the bundle to your dependencies:

composer require venca-x/social-login:~1.0.0
Final composer.json:
// composer.json
{
   // ...
   "require": {
       // ...
       "facebook/graph-sdk" : "^5.4",
       "google/apiclient": "~2.0",
       "kertz/twitteroauth": "dev-master",
       "venca-x/social-login": "~1.0.0"
   }
}

Configuration

config.neon

	parameters:
		facebook:
			appId: '123456789'
			appSecret: '987654321'
			callbackURL: 'http://www.muj-web.cz/homepage/facebook-login'
		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)

BasePresenter.php

    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" ) );		
    }


    //$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();
    ...
    <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>
    public function actionTwitterLogin()
    {
        $this->redirectUrl( $this->socialLogin->twitter->getLoginUrl( $this->presenter->link( '//Homepage:googleLogin' ) ) );
    }

HomepagePresenter.php

    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");
        }
    }
    ...

Registration

Facebook

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

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

Twitter

Register a new app at dev.twitter.com/apps/

social-login's People

Contributors

venca-x avatar pitrrs avatar kubiq avatar

Watchers

James Cloos avatar Starbuck avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.