-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
2,310 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.idea/ | ||
/vendor/ | ||
composer.lock | ||
_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# user | ||
Api base authentication and user managment via laminas and pi | ||
Api base authentication and user management via laminas and pi engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "pi/user", | ||
"description": "Api base authentication and user management via laminas and pi engine", | ||
"license": "BSD-3-Clause", | ||
"keywords": [ | ||
"Pi", | ||
"Pi Engine", | ||
"Laminas", | ||
"Laminas MVC", | ||
"User management", | ||
"User management", | ||
"Psr", | ||
"MultiTenant", | ||
"SaaS" | ||
], | ||
"homepage": "https://piengine.org", | ||
"authors": [ | ||
{ | ||
"name": "Hossein Azizabadi Farahani", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.4 || ~8.0.0", | ||
"ext-ctype": "*", | ||
"ext-fileinfo": "*", | ||
"ext-gd": "*", | ||
"ext-json": "*", | ||
"ext-mbstring": "*", | ||
"ext-pdo": "*", | ||
"ext-spl": "*", | ||
"lib-curl": "*", | ||
|
||
"laminas/laminas-mvc": "^3.1.1", | ||
"laminas/laminas-mvc-i18n": "^1.2.0", | ||
"laminas/laminas-mvc-plugins": "^1.1.0", | ||
"laminas/laminas-mvc-middleware": "^2.2", | ||
"laminas/laminas-db": "^2.12.0", | ||
"laminas/laminas-json": "^3.2", | ||
"laminas/laminas-log": "^2.13.1", | ||
"laminas/laminas-authentication": "^2.9", | ||
"laminas/laminas-crypt": "^3.6", | ||
"laminas/laminas-http": "^2.15", | ||
"laminas/laminas-eventmanager": "^3.4", | ||
"laminas/laminas-cache": "^3.1", | ||
"laminas/laminas-cache-storage-adapter-redis": "^2.1", | ||
"laminas/laminas-serializer": "^2.12", | ||
"laminas/laminas-inputfilter": "^2.13", | ||
"firebase/php-jwt": "^5.5" | ||
}, | ||
|
||
"autoload": { | ||
"psr-4": { | ||
"Pi\\User\\": "src/" | ||
} | ||
}, | ||
|
||
"suggest": { | ||
"ext-apc": "for opcode cache and system persistent data", | ||
"ext-discount": "for Markdown text parsing", | ||
"ext-intl": "for i18n features" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
return [ | ||
'jwt' => [ | ||
'secret' => 'xt2468xc9mh5hvnal80rng36bbk16co4', | ||
'exp_access' => 900, // 15 min | ||
'exp_refresh' => 7776000, // 90 days | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
namespace User; | ||
|
||
use Laminas\Mvc\Middleware\PipeSpec; | ||
use Laminas\Router\Http\Literal; | ||
|
||
return [ | ||
'service_manager' => [ | ||
'aliases' => [ | ||
Repository\AccountRepositoryInterface::class => Repository\AccountRepository::class, | ||
Service\ServiceInterface::class => Service\AccountService::class, | ||
], | ||
'factories' => [ | ||
Repository\AccountRepository::class => Factory\Repository\AccountRepositoryFactory::class, | ||
Service\AccountService::class => Factory\Service\AccountServiceFactory::class, | ||
Service\TokenService::class => Factory\Service\TokenServiceFactory::class, | ||
Service\CacheService::class => Factory\Service\CacheServiceFactory::class, | ||
Middleware\AuthenticationMiddleware::class => Factory\Middleware\AuthenticationMiddlewareFactory::class, | ||
Middleware\SecurityMiddleware::class => Factory\Middleware\SecurityMiddlewareFactory::class, | ||
Middleware\ValidationMiddleware::class => Factory\Middleware\ValidationMiddlewareFactory::class, | ||
Validator\EmailValidator::class => Factory\Validator\EmailValidatorFactory::class, | ||
Validator\IdentityValidator::class => Factory\Validator\IdentityValidatorFactory::class, | ||
Validator\NameValidator::class => Factory\Validator\NameValidatorFactory::class, | ||
Handler\Api\ProfileHandler::class => Factory\Handler\Api\ProfileHandlerFactory::class, | ||
Handler\Api\LoginHandler::class => Factory\Handler\Api\LoginHandlerFactory::class, | ||
Handler\Api\LogoutHandler::class => Factory\Handler\Api\LogoutHandlerFactory::class, | ||
Handler\Api\RegisterHandler::class => Factory\Handler\Api\RegisterHandlerFactory::class, | ||
Handler\Api\RefreshHandler::class => Factory\Handler\Api\RefreshHandlerFactory::class, | ||
Handler\ErrorHandler::class => Factory\Handler\ErrorHandlerFactory::class, | ||
], | ||
], | ||
|
||
'router' => [ | ||
'routes' => [ | ||
'user' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/user', | ||
'defaults' => [], | ||
], | ||
'child_routes' => [ | ||
'login' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/login', | ||
'defaults' => [ | ||
'controller' => PipeSpec::class, | ||
'middleware' => new PipeSpec( | ||
Middleware\ValidationMiddleware::class, | ||
Middleware\SecurityMiddleware::class, | ||
Handler\Api\LoginHandler::class | ||
), | ||
], | ||
], | ||
], | ||
'logout' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/logout', | ||
'defaults' => [ | ||
'controller' => PipeSpec::class, | ||
'middleware' => new PipeSpec( | ||
Middleware\AuthenticationMiddleware::class, | ||
Middleware\SecurityMiddleware::class, | ||
Handler\Api\LogoutHandler::class | ||
), | ||
], | ||
], | ||
], | ||
'register' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/register', | ||
'defaults' => [ | ||
'controller' => PipeSpec::class, | ||
'middleware' => new PipeSpec( | ||
Middleware\ValidationMiddleware::class, | ||
Middleware\SecurityMiddleware::class, | ||
Handler\Api\RegisterHandler::class | ||
), | ||
], | ||
], | ||
], | ||
'profile' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/profile', | ||
'defaults' => [ | ||
'controller' => PipeSpec::class, | ||
'middleware' => new PipeSpec( | ||
Middleware\AuthenticationMiddleware::class, | ||
Middleware\SecurityMiddleware::class, | ||
Handler\Api\ProfileHandler::class | ||
), | ||
], | ||
], | ||
], | ||
'refresh' => [ | ||
'type' => Literal::class, | ||
'options' => [ | ||
'route' => '/refresh', | ||
'defaults' => [ | ||
'controller' => PipeSpec::class, | ||
'middleware' => new PipeSpec( | ||
Middleware\AuthenticationMiddleware::class, | ||
Middleware\SecurityMiddleware::class, | ||
Handler\Api\RefreshHandler::class | ||
), | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
|
||
'view_manager' => [ | ||
'strategies' => [ | ||
'ViewJsonStrategy', | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE `account` | ||
( | ||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(255) DEFAULT NULL, | ||
`identity` VARCHAR(128) DEFAULT NULL, | ||
`email` VARCHAR(128) DEFAULT NULL, | ||
`credential` VARCHAR(255) NOT NULL DEFAULT '', | ||
`status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', | ||
`time_created` INT(10) UNSIGNED NOT NULL DEFAULT '0', | ||
`time_activated` INT(10) UNSIGNED NOT NULL DEFAULT '0', | ||
`time_disabled` INT(10) UNSIGNED NOT NULL DEFAULT '0', | ||
`time_deleted` INT(10) UNSIGNED NOT NULL DEFAULT '0', | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `identity` (`identity`), | ||
UNIQUE KEY `email` (`email`), | ||
KEY `name` (`name`), | ||
KEY `status` (`status`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace User\Factory\Handler\Api; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use User\Handler\Api\LoginHandler; | ||
use User\Service\AccountService; | ||
use User\Service\TokenService; | ||
|
||
class LoginHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param null|array $options | ||
* @return LoginHandler | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): LoginHandler | ||
{ | ||
return new LoginHandler( | ||
$container->get(ResponseFactoryInterface::class), | ||
$container->get(StreamFactoryInterface::class), | ||
$container->get(AccountService::class), | ||
$container->get(TokenService::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace User\Factory\Handler\Api; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use User\Handler\Api\LogoutHandler; | ||
use User\Service\AccountService; | ||
use User\Service\TokenService; | ||
|
||
class LogoutHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param null|array $options | ||
* @return LogoutHandler | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): LogoutHandler | ||
{ | ||
return new LogoutHandler( | ||
$container->get(ResponseFactoryInterface::class), | ||
$container->get(StreamFactoryInterface::class), | ||
$container->get(AccountService::class), | ||
$container->get(TokenService::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace User\Factory\Handler\Api; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use User\Handler\Api\ProfileHandler; | ||
use User\Service\AccountService; | ||
use User\Service\TokenService; | ||
|
||
class ProfileHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param null|array $options | ||
* @return ProfileHandler | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ProfileHandler | ||
{ | ||
return new ProfileHandler( | ||
$container->get(ResponseFactoryInterface::class), | ||
$container->get(StreamFactoryInterface::class), | ||
$container->get(AccountService::class), | ||
$container->get(TokenService::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace User\Factory\Handler\Api; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use User\Handler\Api\RefreshHandler; | ||
use User\Service\AccountService; | ||
use User\Service\TokenService; | ||
|
||
class RefreshHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param null|array $options | ||
* @return RefreshHandler | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RefreshHandler | ||
{ | ||
return new RefreshHandler( | ||
$container->get(ResponseFactoryInterface::class), | ||
$container->get(StreamFactoryInterface::class), | ||
$container->get(AccountService::class), | ||
$container->get(TokenService::class) | ||
); | ||
} | ||
} |
Oops, something went wrong.