Download the PHP package oppai/silex-simpleuser without Composer

On this page you can find all versions of the php package oppai/silex-simpleuser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package silex-simpleuser

Simple user provider for Silex

A simple database-backed user provider for use with the Silex SecurityServiceProvider.

In addition to the user provider, this package also includes a controller provider that can optionally set up simple routes and controllers for form-based authentication.

Overview

SimpleUser is intended to be an easy way to get up and running with user authentication in the Silex PHP microframework. Silex has built-in support for the Symfony 2 Security component, which is powerful, but requires writing a lot of boilerplate user management code before it can be used. SimpleUser provides a simple implementation of this missing user management piece for the Security component.

If your Silex application just needs a user authentication layer with a minimal user model, SimpleUser may work fine for you as-is. If you have more complex requirements, you may want to extend the SimpleUser classes, or you may prefer to fork the project and use it as a reference implementation. You should feel free to do either one (this is open source software under the BSD license).

The SimpleUser package provides the following features:

Quick start example config

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

Add this to your composer.json and then run composer update:

"require": {
    "silex/silex": "1.0.*@dev"
    , "doctrine/dbal": "~2.2"
    , "symfony/security": "~2.1"
    , "symfony/twig-bridge": "~2.1"
    , "jasongrimes/silex-simpleuser": "~0.6.3"
}

Add this to your Silex application:

use Silex\Provider;

$app->register(new Provider\DoctrineServiceProvider(), array('db.options' => array(
    'driver'   => 'pdo_mysql',
    'dbname' => 'my_app',
    'host' => 'localhost',
    'user' => 'mydbuser',
    'password' => 'mydbpassword',
)));

$app->register(new Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        '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']; }),
        ),
    ),
));
// Note: As of this writing, RememberMeServiceProvider must be registered *after* SecurityServiceProvider or SecurityServiceProvider
// throws 'InvalidArgumentException' with message 'Identifier "security.remember_me.service.secured_area" is not defined.'
$app->register(new Provider\RememberMeServiceProvider());

// These services are only required if you use the optional SimpleUser controller provider for form-based authentication.
$app->register(new Provider\SessionServiceProvider()); 
$app->register(new Provider\ServiceControllerServiceProvider()); 
$app->register(new Provider\UrlGeneratorServiceProvider()); 
$app->register(new Provider\TwigServiceProvider());

// Register the SimpleUser service provider.
$app->register($u = new SimpleUser\UserServiceProvider());

// Optionally mount the SimpleUser controller provider.
$app->mount('/user', $u);

Create the user database:

mysql -uUSER -pPASSWORD MYDBNAME < vendor/jasongrimes/silex-simpleuser/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.)

Alternately, you can create an admin account with the user manager:

$user = $app['user.manager']->createUser('[email protected]', 'MySeCrEtPaSsWoRd', 'John Doe', array('ROLE_ADMIN'));
$app['user.manager']->insert($user);

Requirements

SimpleUser depends on the DoctrineServiceProvider. (This provides a basic DBAL--database abstraction layer--not the full Doctrine 2 ORM.)

In addition, if you want to use the optional controller provider to set up simple routes for form-based authentication and user management, the Session, Service Controller, Url Generator, and Twig service providers are also required.

These all come with the stock Silex distribution except for some Twig features, which must be added as a dependency in composer.json like this:

"require": {
    "symfony/twig-bridge": "~2.1"
}

Enable Doctrine something like this:

use Silex\Provider;

$app->register(new Provider\DoctrineServiceProvider(), array('db.options' => $config['db']));

Enable the additional service providers like this:

$app->register(new Provider\SessionServiceProvider()); 
$app->register(new Provider\ServiceControllerServiceProvider()); 
$app->register(new Provider\UrlGeneratorServiceProvider()); 
$app->register(new Provider\TwigServiceProvider());

Installing SimpleUser

Add the jasongrimes/silex-simpleuser dependency to the requires section of your composer.json file.

Create the users database in MySQL (after downloading the package with composer):

mysql -uUSER -pPASSWORD MYDBNAME < vendor/jasongrimes/sql/mysql.sql

Register the service in your Silex application:

$userServiceProvider = new SimpleUser\UserServiceProvider();
$app->register($userServiceProvider);

The following services will now be available:

Configuring the Security service to use the SimpleUser user provider

To configure the Silex security service to use the SimpleUser\UserManager as its user provider, set the users key to the user.manager service like this:

$app->register(new Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        'secured_area' => array(

            'users' => $app->share(function($app) { return $app['user.manager']; }),
            // ...
        ),
    ),
));

Using the controller provider

In addition to registering services, the SimpleUser\UserServiceProvider also acts as a controller provider. It defines some routes that can be used for logging in and managing users.

You can mount the user routes like this:

// Register SimpleUser services.
$userServiceProvider = new SimpleUser\UserServiceProvider();
$app->register($userServiceProvider);

// Mount SimpleUser routes.
$app->mount('/user', $userServiceProvider);

The following routes are provided. (In this example they are mounted under /user, but that can be changed by altering the mount() parameter above.)

Route path Route name  
/user/login user.login The login form.
/user/login_check user.login_check Process the login submission. The login form POSTs here.
/user/logout user.logout Log out the current user.
/user/register user.register Form to create a new user.
/user user View the profile of the current user.
/user/{id} user.view View a user profile.
/user/{id}/edit user.edit Edit a user.
/user/list user.list List users.

Configure the firewall to use these routes for form-based authentication. (Replace /user with whatever mount point you used in mount() above).

$app->register(new Silex\Provider\SecurityServiceProvider(), array(
    'security.firewalls' => array(
        'secured_area' => array(
            'pattern' => '^.*$',
            'anonymous' => true,
            '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']; }),
        ),
    ),
));

Customizing views

Changing the layout template

The view scripts all extend a base Twig template that provides the page layout. By default, this layout template is set to @user/layout.twig, stored in src/SimpleUser/views/layout.twig. You'll almost certainly want to change this. Create your own Twig layout template (copying and pasting as necessary from the default template), and then set the new template in the user controller:

$app['user.controller']->setLayoutTemplate('mylayout.twig');
$app['user.controller']->setEditTemplate('myedit.twig');
$app['user.controller']->setListTemplate('mylist.twig');
$app['user.controller']->setLoginTemplate('mylogin.twig');
$app['user.controller']->registerTemplate('myregister.twig');
$app['user.controller']->setViewTemplate('myview.twig');

Access control

The SimpleUser\UserServiceProvider sets up custom access control attributes for testing whether the viewer can edit a user.

By default, users can edit their own user account, and those with ROLE_ADMIN can edit any user. Override SimpleUser\EditUserVoter to change these privileges.

In a controller, control access like this:

// Test if the viewer has access to edit the given $user
if ($app['security']->isGranted('EDIT_USER', $user)) { ... }

// You can also test access by user ID without instantiating a User, ex. in a before() middleware
$app->post('/user/{id}/edit', 'user.controller:editAction')
    ->before(function(Request $request) use ($app) {
        if (!$app['security']->isGranted('EDIT_USER_ID', $request->get('id')) { 
            throw new AccessDeniedException();
        }
    });

In a Twig template, control access like this:

{% if is_granted('EDIT_USER', user) %}
    ...
{% endif %}

All versions of silex-simpleuser with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oppai/silex-simpleuser contains the following files

Loading the files please wait ....