Skip to content

vas3a/AjaxAuthenticationBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Ajax Authentication Symfony Bundle

Instalation:

A) Add AjaxAuthBundle to your composer.json

{
    ...
    "repositories":[
        {
            "type": "vcs",
            "url": "git://github.com/vas3a/AjaxAuthenticationBundle.git"
        }
    ],
    "require":{
        ...
        "smth/ajax-authentication-bundle":"dev-master"
    }
}

B) Enable the bundle

Enable the bundle in the kernel:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Smth\AjaxAuthBundle\AjaxAuthBundle(),
    );
}

C) Import the routing

Import the redirect.xml routing file in your own routing file.

# app/config/routing.yml
ajax_auth:
    resource: "@AjaxAuthBundle/Resources/config/routing.yml"
    prefix:   /connect

Note:

To prevent strange issues, this route should be imported before your custom ones.

D) Configure the bundle

Add the following parameters to your security.yml or config.yml:

// app/security.yml

ajax_auth:
    default_redirect_path     : _default # where to redirect after login
    always_use_default_path   : false
    user_registration_handler : registration.handler # see explanation bellow

Usage:

1) Define your Registration Handler

You need to define a registration handler, which will be called when a user tries to connect with Gacebook or GooglePlus.

First, add a service in your services.yml:

// YourBundle/Resources/config/services.yml
parameters:
    registration.handler.class: Namespace\YourBundle\Authentication\UserRegistrationHandler

services:
    registration.handler:
        class: "%registration.handler.class%"
        parent: ajax_auth.user_registration.handler

Then, define your handler:

// YourBundle/Authentication/UserRegisterHandler.php

use Smth\AjaxAuthBundle\Security\Authentication\UserRegistrationHandler;

class UserRegisterHandler extends UserRegistrationHandler
{
    /**
    * $publicUser - user received from Facebook/Google
    */
    public function handleUser($publicUser){
        /**
        * handle the user: 
        *   register or authenticate him (
        *       use 
        *           $this->authenticateUser(UserInterface $user);
        *       or
        *           %this->authenticationFailed(string $errorMessage);
        *   )
        */
    }
}

2) Configure the front-end part.

In your twig template, use:

{{ AjaxAuthScript({'facebook':'your_facebook_app_id', 'google':'your_google_app_id'}) }}

Note:

** If you don't want to use either of the applications, simply don't provide an app_id

** Your login form should have the following proprieties:

  • id: #ajax-login
  • username input's name: _username
  • password input's name: _password
  • facebook button id: #ajax-fb-btn
  • google button id: #ajax-g-btn

TODO:

Implement remember me service

About

Symfony Bundle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published