2017 © Pedro Peláez
 

library phalcon-user-plugin

User plugin for Phalcon PHP framework

image

crada/phalcon-user-plugin

User plugin for Phalcon PHP framework

  • Wednesday, July 18, 2018
  • by calin.rada
  • Repository
  • 30 Watchers
  • 185 Stars
  • 1,265 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 72 Forks
  • 10 Open issues
  • 34 Versions
  • 3 % Grown

The README.md

IMPORATNT! You should switch to branch v3.0.0

We have switched to facebook/graph-sdk 5.4 !, (*1)

$ composer require crada/phalcon-user-plugin:^3.0

Phalcon User Plugin (v 2.0)

About

This is a plugin based on Vokuro ACL idea., (*2)

Features

  • Login / Register with Facebook account
  • Login / Register with LinkedIn account
  • Login / Register with Twitter account
  • Login / Register with Google account
  • Change password
  • Password recovery by email
  • Protect different areas from your website, where a user must be logged in, in order to have access
  • Protect different actions, based on the ACL list for each user
  • User profile: birth date, birth location, current location, profile picture
  • Locations - save locations using google API - see Wiki for examples
  • Simple notifications system

Installation

The recommended installation is via Composer. Just add the following line to your composer.json:, (*3)

{
    "require": {
        "crada/phalcon-user-plugin": "~2.0"
    }
}
$ php composer.phar update

Plug it

Add the following lines where to your events manager:, (*4)


$security = new \Phalcon\UserPlugin\Plugin\Security($di); $eventsManager->attach('dispatch', $security);

Full example code:, (*5)

use Phalcon\UserPlugin\Plugin\Security as SecurityPlugin;
use Phalcon\Mvc\Dispatcher;

$di->setShared(
    'dispatcher',
    function() use ($di) {
        $eventsManager = $di->getShared('eventsManager');

        $security = new SecurityPlugin($di);
        $eventsManager->attach('dispatch', $security);

        $dispatcher = new Dispatcher();
        $dispatcher->setEventsManager($eventsManager);

        return $dispatcher;
    }
);

Register Auth, Mail and Acl services, (*6)

use Phalcon\UserPlugin\Auth\Auth;
use Phalcon\UserPlugin\Acl\Acl;
use Phalcon\UserPlugin\Mail\Mail;

$di->setShared(
    'auth',
    function() {
        return new Auth();
    }
);

$di->setShared(
    'acl',
    function() {
        return new Acl();
    }
);

$di->setShared(
    'mail',
    function() {
        return new Mail();
    }
);

Configuration

You must add configuration keys to your config.php file. If you are using a multimodule application, i recommend you to set up the configuration separately for each module., (*7)

Configuration examples

In the example bellow, you will treat your website as public, EXCEPT the actions ACCOUNT and PROFILE from the USER controller:, (*8)

'pup' => [
    'redirect' => [
        'success' => 'user/profile',
        'failure' => 'user/login'    
    ],
    'resources' => [
        'type' => 'public',
        'resources' => [
            '*' => [
                // All except
                'user' => ['account', 'profile']
            ]
        ]
    ]
];

In the example bellow, the ONLY PUBLIC resources are the actions LOGIN and REGISTER from the USER controller:, (*9)

'pup' => [
    'redirect' => [
        'success' => 'user/profile',
        'failure' => 'user/login'    
    ],
    'resources' => [
        'type' => 'public',
        'resources' => [
            'user' => [
                'user' => ['login', 'register']
            ]
        ]
    ]
];

In the example bellow, you will treat your website as private, EXCEPT the actions LOGIN and REGISTER from the USER controller:, (*10)

'pup' => [
    'redirect' => [
        'success' => 'user/profile',
        'failure' => 'user/login'    
    ],
    'resources' => [
        'type' => 'private',
        'resources' => [
            '*' => [
                // All except
                'user' => ['login', 'register']
            ]
        ]
    ]
];

In the example bellow, the ONLY PRIVATE resources are the actions ACCOUNT and PROFILE from the USER controller:, (*11)

'pup' => [
    'redirect' => [
        'success' => 'user/profile',
        'failure' => 'user/login'    
    ],
    'resources' => [
        'type' => 'private',
        'resources' => [
            'user' => [
                'user' => ['account', 'profile']
            ]
        ]
    ]
];

Configuration example with connectors:, (*12)

// phalcon-user-plugin
'pup' => [
    'redirect' => [
        'success' => 'user/profile',
        'failure' => 'user/login'    
    ],
    'resources' => [
        'type' => 'public',
        'resources' => [
            '*' => [
                // All except
                'user' => ['account', 'profile']
            ]
        ]
    ],
    'connectors' => [
        'facebook' => [
            'appId' => 'YOUR_FACEBOOK_APP_ID',
            'secret' => 'YOUR_FACEBOOK_APP_SECRET'
        ],
        'linkedIn' => [
            'api_key' => 'YOUR_LINKED_IN_APP_ID',
            'api_secret' => 'YOUR_LINKED_IN_APP_SECRET',
            'callback_url' => 'CALLBACK_URL'
        ],
        'twitter' => [
            'consumer_key' => 'TWITTER_CONSUMER_KEY',
            'consumer_secret' => 'TWITTER_CONSUMER_SECRET',
            // Leave empty if you don't want to set it
            'user_agent' => 'YOUR_APPLICATION_NAME'
        ],
        'google' => [
            'application_name' => 'YOUR_APPLICATION_NAME',
            'client_id' => 'YOUR_CLIENT_ID',
            'client_secret' => 'YOUR_CLIENT_SECRET',
            'developer_key' => 'YOUR_DEVELOPER_KEY',
            'redirect_uri' => 'YOUR_REDIRECT_URI'
        ]
    ]
];

Example controller

  • For a complete controller example read the Wiki page: https://github.com/calinrada/PhalconUserPlugin/wiki/Controller
class UserController extends Controller
{
    /**
     * Login user
     * @return \Phalcon\Http\ResponseInterface
     */
    public function loginAction()
    {
        if (true === $this->auth->isUserSignedIn()) {
            $this->response->redirect(['action' => 'profile']);
        }

        $form = new LoginForm();

        try {
            $this->auth->login($form);
        } catch (AuthException $e) {
            $this->flash->error($e->getMessage());
        }

        $this->view->form = $form;
    }

    /**
     * Login with Facebook account
     */
    public function loginWithFacebookAction()
    {
        try {
            $this->view->disable();
            return $this->auth->loginWithFacebook();
        } catch(AuthException $e) {
            $this->flash->error('There was an error connectiong to Facebook.');
        }
    }

    /**
     * Login with LinkedIn account
     */
    public function loginWithLinkedInAction()
    {
        try {
            $this->view->disable();
            $this->auth->loginWithLinkedIn();
        } catch(AuthException $e) {
            $this->flash->error('There was an error connectiong to LinkedIn.');
        }
    }

    /**
     * Login with Twitter account
     */
    public function loginWithTwitterAction()
    {
        try {
            $this->view->disable();
            $this->auth->loginWithTwitter();
        } catch(AuthException $e) {
            $this->flash->error('There was an error connectiong to Twitter.');
        }
    }

    /**
     * Login with Google account
     */
    public function loginWithGoogleAction()
    {
        try {
            $this->view->disable();
            $this->auth->loginWithGoogle();
        } catch(AuthException $e) {
            $this->flash->error('There was an error connectiong to Google.');
        }
    }

    /**
     * Logout user and clear the data from session
     *
     * @return \Phalcon\Http\ResponseInterface
     */
    public function signoutAction()
    {
        $this->auth->remove();
        return $this->response->redirect('/', true);
    }
}

Known issues

  • Twitter does not provide us the email. We are generating a random email for the user. It is your choice how you handle this

Examples

TODO

  • Implement CRUD templates for ACl, UserManagement, etc

The Versions

18/07 2018

dev-master

9999999-dev https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

20/03 2018

v3.0.0.x-dev

3.0.0.9999999-dev https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

11/12 2017
31/07 2017
21/04 2017
18/04 2017
07/04 2017
03/02 2017
30/12 2016
08/12 2016
07/12 2016
07/12 2016
06/12 2016

3.0.1

3.0.1.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

06/12 2016

3.0.0

3.0.0.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

06/12 2016

2.0.7

2.0.7.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

18/08 2016

2.0.6

2.0.6.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

07/09 2015

2.0.5

2.0.5.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

19/06 2015

2.0.4

2.0.4.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

23/04 2015

dev-2.0-dev

dev-2.0-dev https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

23/04 2015

2.0.3

2.0.3.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

16/03 2015

2.0.2

2.0.2.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

16/03 2015

2.0.1

2.0.1.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook twitter phalcon linkedin google-plus

11/03 2015

2.0

2.0.0.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

01/03 2015

1.1.13

1.1.13.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

19/02 2015

1.1.12

1.1.12.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

19/02 2015

1.1.11

1.1.11.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

05/02 2015

1.1.9

1.1.9.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

08/01 2015

1.1.10

1.1.10.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

09/10 2014

1.1.8

1.1.8.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

16/09 2014

1.1.7

1.1.7.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

14/06 2014

1.1.6

1.1.6.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon

13/06 2014

1.1.5

1.1.5.0 https://github.com/calinrada/PhalconUserPlugin

User plugin for Phalcon PHP framework

  Sources   Download

MIT

The Requires

 

by Calin Rada

user login facebook phalcon