2017 © Pedro Peláez
 

library silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

image

sinasalek/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  • Saturday, January 28, 2017
  • by sinasalek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 38 Versions
  • 0 % Grown

The README.md

User Provider for Silex

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

A simple, extensible, database-backed user provider for the Silex security service., (*2)

The User Provider is an easy way to set up user accounts (authentication, authorization, and user administration) in the Silex PHP micro-framework. It provides drop-in services for Silex that implement the missing user management pieces for the Security component. It includes a basic User model, a database-backed user manager, controllers and views for user administration, and various supporting features., (*3)

Usage

Dependencies

  • PHP ~5.4
  • Silex ~1.0
  • Doctrine DBAL ~2.4
  • Symfony Security ~2.3

Demo

Quick start example config

This configuration should work out of the box to get you up and running quickly. See below for additional details., (*4)

Install with composer. This command will automatically install the latest stable version:, (*5)

$ composer require rootlogin/silex-userprovider

Set up your Silex application something like this:, (*6)

<?php

use Silex\Application;
use Silex\Provider;

//
// Application setup
//

$app = new Application();
$app->register(new Provider\DoctrineServiceProvider());
$app->register(new Provider\SecurityServiceProvider());
$app->register(new Provider\RememberMeServiceProvider());
$app->register(new Provider\SessionServiceProvider());
$app->register(new Provider\ServiceControllerServiceProvider());
$app->register(new Provider\UrlGeneratorServiceProvider());
$app->register(new Provider\TwigServiceProvider());
$app->register(new Provider\SwiftmailerServiceProvider());

// Register the UserProvider service provider.
$app->register(new \rootLogin\UserProvider\Provider\UserProviderServiceProvider());

// ...

//
// Controllers
//

// Mount the user controller routes:
$app->mount('/user', new \rootLogin\UserProvider\Provider\UserProviderControllerProvider());

/*
// Other routes and controllers...
$app->get('/', function () use ($app) {
    return $app['twig']->render('index.twig', array());
});
*/

// ...

//
// Configuration
//

// UserProvider options. See config reference below for details.
$app['user.options'] = array();

// Security config. See http://silex.sensiolabs.org/doc/providers/security.html for details.
$app['security.firewalls'] = array(
    /* // Ensure that the login page is accessible to all, if you set anonymous => false below.
    'login' => array(
        'pattern' => '^/user/login$',
    ), */
    'secured_area' => array(
        'pattern' => '^.*$',
        'anonymous' => true,
        'remember_me' => array(),
        'form' => array(
            'login_path' => '/user/login',
            'check_path' => '/user/login_check',
        ),
        'logout' => array(
            'logout_path' => '/user/logout',
        ),
        'users' => $app->share(function($app) { return $app['user.manager']; }),
    ),
);

// Mailer config. See http://silex.sensiolabs.org/doc/providers/swiftmailer.html
$app['swiftmailer.options'] = array();

// Database config. See http://silex.sensiolabs.org/doc/providers/doctrine.html
$app['db.options'] = array(
    'driver'   => 'pdo_mysql',
    'host' => 'localhost',
    'dbname' => 'mydbname',
    'user' => 'mydbuser',
    'password' => 'mydbpassword',
);

return $app;

Create the user database:, (*7)

mysql -uUSER -pPASSWORD MYDBNAME < vendor/rootlogin/silex-userprovider/sql/mysql.sql

You should now be able to create an account at the /user/register URL. Make the new account an administrator by editing the record directly in the database and setting the users.roles column to ROLE_USER,ROLE_ADMIN. (After you have one admin account, it can grant the admin role to others via the web interface.), (*8)

Config options

All of these options are optional. The UserProvider can work without any configuration at all, or you can customize one or more of the following options. The default values are shown below., (*9)

$app['user.options'] = array(

    // Specify custom view templates here.
    'templates' => array(
        'layout' => '@user/layout.twig',
        'register' => '@user/register.twig',
        'register-confirmation-sent' => '@user/register-confirmation-sent.twig',
        'login' => '@user/login.twig',
        'login-confirmation-needed' => '@user/login-confirmation-needed.twig',
        'forgot-password' => '@user/forgot-password.twig',
        'reset-password' => '@user/reset-password.twig',
        'view' => '@user/view.twig',
        'edit' => '@user/edit.twig',
        'list' => '@user/list.twig',
    ),

    // Configure the user mailer for sending password reset and email confirmation messages.
    'mailer' => array(
        'enabled' => true, // When false, email notifications are not sent (they're silently discarded).
        'fromEmail' => array(
            'address' => 'do-not-reply@' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : gethostname()),
            'name' => null,
        ),
    ),

    'emailConfirmation' => array(
        'required' => false, // Whether to require email confirmation before enabling new accounts.
        'template' => '@user/email/confirm-email.twig',
    ),

    'passwordReset' => array(
        'template' => '@user/email/reset-password.twig',
        'tokenTTL' => 86400, // How many seconds the reset token is valid for. Default: 1 day.
    ),

    // Set this to use a custom User class.
    'userClass' => 'rootLogin\UserProvider\Entity\User',

    // Whether to require that users have a username (default: false).
    // By default, users sign in with their email address instead.
    'isUsernameRequired' => false,

    // A list of custom fields to support in the edit controller. (DBAL only)
    'editCustomFields' => array(),

    // Override table names, if necessary. (Works only in DBAL mode)
    'userTableName' => 'users',
    'userCustomFieldsTableName' => 'user_custom_fields',

    //Override Column names, if necessary
    'userColumns' => array(
        'id' => 'id',
        'email' => 'email',
        'password' => 'password',
        'salt' => 'salt',
        'roles' => 'roles',
        'name' => 'name',
        'time_created' => 'time_created',
        'username' => 'username',
        'isEnabled' => 'isEnabled',
        'confirmationToken' => 'confirmationToken',
        'timePasswordResetRequested' => 'timePasswordResetRequested',
        //Custom Fields
        'user_id' => 'user_id',
        'attribute' => 'attribute',
        'value' => 'value',
    ),

    // Use Doctrine Orm if available
    "useOrmIfAvailable" => true
);

Commandline

If you have enabled the symfony console, as with saxulum-console for example, the provider will add some commands to the console:, (*10)

  • simpleuser:create: Create an user
  • simpleuser:list: List users
  • simpleuser:delete: Delete an user

Doctrine ORM

The provider uses the Doctrine Orm (Object-relational mapper) automatically, if the necessairy provider are found., (*11)

An auto migration is no possible., (*12)

Developer documentation

Contribution

Everyone is welcome to contribute to this project. The only thing you need to do is opening a pull request or an issue. By pushing code to the repository or doing pull requests, you accept that your code will be published under the GNU LGPL., (*13)

Licensing

The original library was developed by jasongrimes under the BSD Clause-2 license. However, I wanted a transition to the LGPL v3.0, so please be aware of the fact that all codes from now on are released under the GNU LGPL v3.0. I try to make it as transparent as possible. If you want to get sure that you only use the BSD licensed code, please use a version lower or equal 2.0.1., (*14)

Project documentation

About the roots

This is a fork of jasongrimes/silex-simpleuser. it has been made one year after the abandonment of the original project. I will maintain and keep it up-to-date under this name. Until version 3.0 there should be complete compatibility., (*15)

More information

See the Silex SimpleUser tutorial., (*16)

Changelog

  • Version 3.0.0
    • Changed namespace
    • Added informations about the licensing.
    • Improved documentation
    • Updated tests
    • Renamed commands
    • Works with Doctrine DBAL and ORM, as you wish
  • Version 2.0.2
    • Mainly changes in the documentation
    • Added commands for creating, listing and deleting users
  • Version 2.0.1
    • Last version from jasongrimes.
    • No changelog was maintained before.

The Versions

15/02 2016

v3.0.0-b2

3.0.0.0-beta2 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

user silex user provider silex user provider

14/02 2016

v3.0.0-b1

3.0.0.0-beta1 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

user silex user provider silex user provider

14/02 2016

v3.0.0-a2

3.0.0.0-alpha2 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

user silex user provider silex user provider

13/02 2016

dev-master

9999999-dev http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

user silex user provider silex user provider

13/02 2016

v3.0.0-a1

3.0.0.0-alpha1 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

user silex user provider silex user provider

09/02 2016

dev-v2_0

dev-v2_0 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider silex user provider

09/02 2016

v2.0.2

2.0.2.0 http://github.com/chrootlogin/silex-userprovider

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider silex user provider

19/08 2015

dev-v3_0

dev-v3_0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

01/11 2014

2.0.1

2.0.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

01/11 2014

2.0

2.0.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

01/11 2014

1.7.1

1.7.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

21/10 2014

1.7

1.7.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

19/10 2014

1.6

1.6.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

19/10 2014

1.5

1.5.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

13/10 2014

1.4.1

1.4.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

12/10 2014

1.4

1.4.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

11/10 2014

1.3.3

1.3.3.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

02/10 2014

1.3.2

1.3.2.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

01/10 2014

1.3.1

1.3.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

01/10 2014

1.3

1.3.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

22/09 2014

1.2.1

1.2.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

18/09 2014

1.2

1.2.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

17/09 2014

1.1

1.1.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

04/09 2014

1.0

1.0.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Jason Grimes

user silex user provider simple user provider

24/08 2014

0.7

0.7.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

24/04 2013

0.6.3

0.6.3.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

24/04 2013

0.6.2

0.6.2.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

22/04 2013

0.6.1

0.6.1.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

21/04 2013

0.6

0.6.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

21/04 2013

0.5

0.5.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

21/04 2013

0.4

0.4.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

16/04 2013

0.3

0.3.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

15/04 2013

0.2

0.2.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider

15/04 2013

0.1

0.1.0.0 http://github.com/jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jason Grimes

user silex user provider simple user provider