2017 © Pedro Peláez
 

library cog-user

Cog module for a very basic and extensible user system

image

mothership-ec/cog-user

Cog module for a very basic and extensible user system

  • Tuesday, May 31, 2016
  • by thomasjthomasj
  • Repository
  • 4 Watchers
  • 0 Stars
  • 2,499 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 2 Forks
  • 15 Open issues
  • 27 Versions
  • 0 % Grown

The README.md

User

The Message\User cogule provides a simple user and permission system., (*1)

Services

todo: list services defined here, (*2)

Events

The following events are fired by this cogule. The event object is always an instance of Message\User\Event\Event., (*3)

  • user.login.attempt: fired when a login attempt is made (only if it passes basic validation), regardless of whether or not the user exists. This event is an instance of Message\User\Event\LoginAttemptEvent.
  • user.login: fired when a user successfully logs in.
  • user.logout: fired when a user successfully logs out.
  • user.password.request: fired when a password reset request is made, only if the user exists.
  • user.password.reset: fired when a user successfully resets their password.
    • Note that if the password was reset via the "forgotten password" system, the user is logged in after this event is fired and the user.login event is then fired.
  • user.create fired when a user is created using the Message\User\Create decorator.
  • user.edit fired when a user is edited using the Message\User\Edit decorator.
    • Note this event is not fired when:
      • The "password request time" is updated or cleared.
      • The "last login time" is updated.
      • The user is added to or removed from a group
  • user.email_confirmed fired when a user confirms their email address (if required)
  • user.group.add fired when a user is added to a group using Message\User\Edit::addToGroup()
  • user.group.remove fired when a user is removed from a group using Message\User\Edit::removeFromGroup()

Users

A user has the following properties:, (*4)

  • An ID
  • An email address
  • An "email confirmed" flag
  • A title (e.g. Mr or Mrs)
  • A forename
  • A surname
  • A "last login" timestamp
  • A "password requested at" timestamp

And the usual metadata for creation and updating. There is no metadata for deletion because when a user is deleted they are hard deleted: they no longer exist in the database., (*5)

If your application or module needs to add more properties to a user, it is recommended to group these properties in a way that makes sense, and create a new model representing that group of properties. The Message\User\User object should remain a simple representation of basic user information., (*6)

For example, in an e-commerce module, address data might be stored for users. In this case, it would make sense to create a model representing a user's address, like so:, (*7)

class UserAddress
{
    public $user;

    public $typeID;

    public $addressLines;
    public $town;
    public $postcode;
    public $countryID;
    public $stateID;
    public $telephone;
}

Groups

A user group is, of course, a simple way of grouping users. The Message\User cogule doesn't define any groups itself, but it provides groups functionality and a framework for any other cogule to define groups., (*8)

To define a group, first you need to create a class that implements Message\User\Group\GroupInterface:, (*9)

<?php

namespace Message\MyModule;

use Message\User\Group;

class SuperAdmin implements Group\GroupInterface
{
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'super-admin';
    }

    /**
     * {@inheritdoc}
     */
    public function getDisplayName()
    {
        return 'Super Administrators';
    }

    /**
     * {@inheritdoc}
     */
    public function getDescription()
    {
        return 'Users with access to everything!';
    }

    /**
     * {@inheritdoc}
     */
    public function registerPermissions(Group\Permissions $permissions)
    {
        // ...
    }
}

Then you just need to add it to the user.groups service definition, which is a collection of user groups available to the system. Any user group that is not added to this collection is not "known" to the system., (*10)

Ideally, groups should be added to the collection on the modules.load.success event. Add an event listener like this to your cogule's events bootstrap:, (*11)

$dispatcher->addListener('modules.load.success', function() use ($services) {
    $services['user.groups']
        ->add(new Message\MyModule\SuperAdmin);
});

Permissions

A simple permissions system is included in this cogule that is built around user groups and route collections or routes., (*12)

Every group must implement the registerPermissions() method that is defined on the Message\User\Group\GroupInterface interface. The argument passed in to this method is an instance of Message\User\Group\Permissions for the appropriate group., (*13)

Within registerPermissions(), a set of permissions can be registered for the group. A group can be granted permission to any of the following:, (*14)

  • All routes within a specific route collection.
  • A specific route.
  • A specific route with specific parameter values.

Here's an example of all three:, (*15)

public function registerPermissions(Permissions $permissions)
{
    // Grants the group access to all routes in the 'my.collection' route collection
    $permissions
        ->addRouteCollection('my.collection');

    // Grants the group access to the `homepage` and `secret.page` route
    $permissions
        ->addRoute('homepage')
        ->addRoute('secret.page');

    // Grants the group access to the `file.view` route only when the `type` parameter equals "image"
    $permissions
        ->addRoute('file.view', array('type' => 'image'));
}

Once any group defines a permission for a route or a route collection, that route or route collection becomes "protected", making it unavailable unless the current user is in a group that has access to the route collection or specific route., (*16)

If the current user does not the appropriate permissions to access a protected route, an Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException is thrown., (*17)

Controllers & Routes

todo: write about the controllers available and the routes, and how to use them in an app, (*18)

The Versions

31/05 2016

dev-develop

dev-develop http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

31/05 2016

dev-master

9999999-dev http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

31/05 2016

2.2.0

2.2.0.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

19/05 2016

dev-user-titles

dev-user-titles http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

06/05 2016

2.1.0

2.1.0.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

15/09 2015

2.0.3

2.0.3.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

07/09 2015

dev-feature/clean-up-user-session-loading

dev-feature/clean-up-user-session-loading http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

14/08 2015

2.0.2

2.0.2.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

30/07 2015

2.0.1

2.0.1.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

29/07 2015

dev-feature/dispatch-event-on-create

dev-feature/dispatch-event-on-create http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

24/02 2015

dev-feature/event-on-user-creation

dev-feature/event-on-user-creation http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

24/02 2015

2.0.0

2.0.0.0 http://mothership.ec

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Mothership Development Team

user accounts account users cog

27/01 2015

1.4.1

1.4.1.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

27/01 2015

1.4.0

1.4.0.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

19/12 2014

dev-feature/create-user-task

dev-feature/create-user-task http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

 

by The Message Development Team

user accounts account users cog

06/10 2014

dev-feature/multiple-currencies

dev-feature/multiple-currencies http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

06/10 2014

1.3.0

1.3.0.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

12/05 2014

1.2.0

1.2.0.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

18/03 2014

1.1.0

1.1.0.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~3.0

 

by The Message Development Team

user accounts account users cog

10/01 2014

1.0.3

1.0.3.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.4.0
  • message/cog ~2.0

 

by The Message Development Team

user accounts account users cog

25/11 2013

dev-feature/fix-premature-session-start

dev-feature/fix-premature-session-start http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.3.0
  • message/cog 1.*

 

by The Message Development Team

user accounts account users cog

25/11 2013

1.0.2

1.0.2.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.3.0
  • message/cog 1.*

 

by The Message Development Team

user accounts account users cog

20/11 2013

1.0.1

1.0.1.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

proprietary

The Requires

  • php >=5.3.0
  • message/cog 1.*

 

by The Message Development Team

user accounts account users cog

17/11 2013

dev-issues/new-user-id

dev-issues/new-user-id http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

The Requires

  • php >=5.3.0
  • message/cog 1.0.*

 

by The Message Development Team

user accounts account users cog

17/11 2013

1.0.0

1.0.0.0 http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

The Requires

  • php >=5.3.0
  • message/cog 1.0.*

 

by The Message Development Team

user accounts account users cog

29/10 2013

dev-ux/improvements

dev-ux/improvements http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

The Requires

  • php >=5.3.0
  • message/cog dev-master

 

by The Message Development Team

user accounts account users cog

06/06 2013

dev-log-in-helper

dev-log-in-helper http://message.co.uk

Cog module for a very basic and extensible user system

  Sources   Download

The Requires

  • php >=5.3.0
  • message/cog dev-master

 

by The Message Development Team

user accounts account users cog