Authentication module for zf2
Very simple authentication from the Box - define accounts config with login and password and use.
Clone this project into your ./vendor/
directory.
Add this project in your composer.json:
"require": {
"t4web/authentication": "~1.0.0"
}
Now tell composer to download Authentication by running the command:
$ php composer.phar update
Enabling it in your application.config.php
file.
<?php
return array(
'modules' => array(
// ...
'T4web\Authentication',
),
// ...
);
For define which page need authorization, you can redeclare need-authorization-callback
, by default:
'need-authorization-callback' => function(RouteMatch $match) {
$name = $match->getMatchedRouteName();
if ($name == 'auth-login') {
return false;
}
if (strpos($name, 'admin') !== false) {
return true;
}
return false;
},
For change auth login form layout you can define layout
route param, for change
redirect uri after success authorization, you can define redirect-to-url
route param:
'router' => array(
'routes' => array(
'auth-login' => array(
'options' => array(
'defaults' => array(
'layout' => 'layout/my_auth_layout',
'redirect-to-url' => '/some/uri',
),
),
),
),
),
By default auth use php array for auth storage, but you can write own:
'service_manager' => [
'factories' => [
Zend\Authentication\Adapter\AdapterInterface::class => Adapter\MyAdapter::class,
]
]
Adapter\MyAdapter
must implement Zend\Authentication\Adapter\ValidatableAdapterInterface
.
This module contain two adapters in the Box PhpArray
and Table
.
This adapter use by default.
For define logins and passwords just describe it in you config in auth-accounts
section:
'auth-accounts' => [
'someUser1' => 'str0ngp@ssw0rd',
'someUser2' => '111',
],
This is wrapper for Zend\Authentication\Adapter\DbTable\CallbackCheckAdapter
, for start use, define it in your config:
'service_manager' => [
'factories' => [
Zend\Authentication\Adapter\AdapterInterface::class => \T4web\Authentication\Adapter\TableFactory::class,
]
],
and describe auth['table-adapter']
config:
'auth' => [
'table-adapter' => [
'table-name' => 'users',
'identity-column' => 'email',
'credential-column' => 'password',
],
],
Unit test runnig from authentication module directory.
$ codeception run unit
For running Functional tests you need create codeception.yml in you project root, like this:
include:
- vendor/t4web/authentication # <- add authentication module tests to include
paths:
log: tests/_output
settings:
colors: true
memory_limit: 1024M
After this you may run functional tests from your project root
$ codeception run