From 2974c4e02c013a3f14a1b27dd00f3e6a923e9aab Mon Sep 17 00:00:00 2001 From: Hossein Azizabadi Farahani Date: Sun, 20 Mar 2022 17:43:50 +0330 Subject: [PATCH] reformat codes --- README.md | 13 +- bin/post-install.php | 6 +- bin/post-remove.php | 6 +- bin/post-update.php | 6 +- composer.json | 4 - data/postman-laminas-user.json | 286 ------------------ src/Factory/Installer/InstallFactory.php | 1 - .../PermissionRepositoryFactory.php | 6 +- .../Repository/RoleRepositoryFactory.php | 2 +- src/Model/Account/Account.php | 16 +- src/Model/Permission/Page.php | 3 - src/Repository/AccountRepository.php | 1 + src/Repository/ProfileRepository.php | 1 + src/Repository/RoleRepository.php | 6 +- src/Repository/RoleRepositoryInterface.php | 2 +- src/Service/AccountService.php | 2 +- src/Service/PermissionService.php | 4 +- src/Validator/MobileValidator.php | 2 +- 18 files changed, 42 insertions(+), 325 deletions(-) delete mode 100644 data/postman-laminas-user.json diff --git a/README.md b/README.md index 0b5d1c6..1d5126d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ -# User module +# User module + Api base authentication and user management via laminas and pi engine ## 1. Important note -This is the first development version of the user module, please don't install it on production projects now, we will work on finishing and testing this module in the next weeks and ready the production version ASAP + +This is the first development version of the user module, please don't install it on production projects now, we will +work on finishing and testing this module in the next weeks and ready the production version ASAP ## 2. Installation + Follow the below steps to install the module via composer ### Step 1 + Run the following to install this library: ```bash @@ -15,6 +20,7 @@ $ composer require pi/user ``` ### Step 2 + Edit `config\modules.config.php` and add `'User'` end of array, for example like this ``` @@ -28,6 +34,7 @@ return [ ``` ### Step 3 + Edit `composer.json` and add this line ``` @@ -40,9 +47,11 @@ Edit `composer.json` and add this line ``` ### Step 4 + Run `composer dump-autoload`. ### Step 5 + Open `data/schema.sql` and create tablas in your database ## 3. List of TODO tasks for this module diff --git a/bin/post-install.php b/bin/post-install.php index 9da0878..3d9ed20 100644 --- a/bin/post-install.php +++ b/bin/post-install.php @@ -12,8 +12,8 @@ 'config' => false, ]; -$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); -$adapter = new Adapter($config->db->toArray()); -$install = new Install($adapter); +$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); +$adapter = new Adapter($config->db->toArray()); +$install = new Install($adapter); echo $install->database(); echo $install->config(); \ No newline at end of file diff --git a/bin/post-remove.php b/bin/post-remove.php index d4bd511..19a7db3 100644 --- a/bin/post-remove.php +++ b/bin/post-remove.php @@ -12,8 +12,8 @@ 'config' => false, ]; -$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); -$adapter = new Adapter($config->db->toArray()); -$install = new Remove($adapter); +$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); +$adapter = new Adapter($config->db->toArray()); +$install = new Remove($adapter); echo $install->database(); echo $install->config(); \ No newline at end of file diff --git a/bin/post-update.php b/bin/post-update.php index 38b1d93..50691ef 100644 --- a/bin/post-update.php +++ b/bin/post-update.php @@ -12,8 +12,8 @@ 'config' => false, ]; -$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); -$adapter = new Adapter($config->db->toArray()); -$install = new Update($adapter); +$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php')); +$adapter = new Adapter($config->db->toArray()); +$install = new Update($adapter); echo $install->database(); echo $install->config(); \ No newline at end of file diff --git a/composer.json b/composer.json index ecd904f..5ce77e9 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,6 @@ "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", @@ -52,13 +51,11 @@ "laminas/laminas-i18n": "^2.14", "firebase/php-jwt": "^5.5" }, - "autoload": { "psr-4": { "User\\": "vendor/pi/user/src/" } }, - "scripts": { "post-install-cmd": [ "php -r 'if (file_exists(\"bin/post-install.php\")) include \"bin/post-install.php\";'" @@ -70,7 +67,6 @@ "php -r 'if (file_exists(\"bin/post-remove.php\")) include \"bin/post-remove.php\";'" ] }, - "suggest": { "ext-apc": "for opcode cache and system persistent data", "ext-discount": "for Markdown text parsing", diff --git a/data/postman-laminas-user.json b/data/postman-laminas-user.json deleted file mode 100644 index 7fee970..0000000 --- a/data/postman-laminas-user.json +++ /dev/null @@ -1,286 +0,0 @@ -{ - "info": { - "name": "Laminas", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "user_register", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "name", - "value": "Usert Test", - "type": "text" - }, - { - "key": "email", - "value": "myemail@gmail.com", - "type": "text" - }, - { - "key": "credential", - "value": "1234asdf", - "type": "text" - } - ] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/register", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "register" - ] - } - }, - "response": [] - }, - { - "name": "user_login", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "identity", - "value": "user", - "type": "text" - }, - { - "key": "credential", - "value": "12345678", - "type": "text" - } - ] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/login", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "login" - ] - } - }, - "response": [] - }, - { - "name": "user_logout", - "request": { - "method": "POST", - "header": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVzZXItYWNjZXNzLTctMDg4YzU5ajUxcWU4MXlkZSIsInVpZCI6IjciLCJpYXQiOjE2NDY3MzE0NjEsImV4cCI6MTY0Nzk0MTA2MSwidHlwZSI6ImFjY2VzcyIsInJvbGVzIjpbIm1lbWJlciJdfQ.H9Iq5lceaUUdKNOb7GD2fh8-TX-O7DcZYtir_maFZAA", - "type": "text" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "all_session", - "value": "1", - "description": "0 or 1 for kill other seactions", - "type": "text" - } - ] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/logout", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "logout" - ] - } - }, - "response": [] - }, - { - "name": "user_profile", - "request": { - "method": "POST", - "header": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVzZXItYWNjZXNzLTcteXlsYmppcXA0YnVreTR1ZSIsInVpZCI6NywiaWF0IjoxNjQ2NzI0MzMyLCJleHAiOjE2NDc5MzM5MzIsInR5cGUiOiJhY2Nlc3MiLCJyb2xlcyI6WyJtZW1iZXIiXX0.xM817wGyw9nSLpngQiVFoQmJ3NYz0TsBI9UzmJErK-w", - "type": "text" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/profile", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "profile" - ] - } - }, - "response": [] - }, - { - "name": "user_update", - "request": { - "method": "POST", - "header": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVzZXItYWNjZXNzLTctdDdlYzN1Mmh0cno2NzNnOSIsInVpZCI6IjciLCJpYXQiOjE2NDY3MjMyNjIsImV4cCI6MTY0NzkzMjg2MiwidHlwZSI6ImFjY2VzcyIsInJvbGVzIjpbIm1lbWJlciJdfQ.4s-eVUex-1rOOhoClhJbzKmujr48TFXZWR8QCdGe-ws", - "type": "text" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVocHhjdWF4OGppa2dyZmEiLCJ1aWQiOiI3IiwiaWF0IjoxNjQ2NTYwNjc5LCJleHAiOjE2NDc3NzAyNzksInR5cGUiOiJhY2Nlc3MiLCJyb2xlcyI6WyJtZW1iZXIiXX0.G7IxFwbo26m1cb9lnZCVregLqIHAhe4wiE7ZA2EU4RE", - "type": "text" - }, - { - "key": "email", - "value": "user@gmail.com", - "type": "text" - }, - { - "key": "name", - "value": "User Test", - "type": "text" - }, - { - "key": "identity", - "value": "user", - "type": "text" - } - ] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/update", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "update" - ] - } - }, - "response": [] - }, - { - "name": "user_password", - "request": { - "method": "POST", - "header": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVzZXItYWNjZXNzLTctdDdlYzN1Mmh0cno2NzNnOSIsInVpZCI6IjciLCJpYXQiOjE2NDY3MjMyNjIsImV4cCI6MTY0NzkzMjg2MiwidHlwZSI6ImFjY2VzcyIsInJvbGVzIjpbIm1lbWJlciJdfQ.4s-eVUex-1rOOhoClhJbzKmujr48TFXZWR8QCdGe-ws", - "type": "text" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "current_credential", - "value": "321321321", - "type": "text" - }, - { - "key": "new_credential", - "value": "12345678", - "type": "text" - } - ] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/password", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "password" - ] - } - }, - "response": [] - }, - { - "name": "user_refresh_token", - "request": { - "method": "POST", - "header": [ - { - "key": "token", - "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InVzZXItcmVmcmVzaC03LW03Y2Fzbm1sM2oxc2s2emYiLCJ1aWQiOiI3IiwiaWF0IjoxNjQ2NzI4MDU0LCJleHAiOjE2NTQ1MDQwNTQsInR5cGUiOiJyZWZyZXNoIn0.GU8BOh4y7LRPGLTtIw5ZGcH54ScRqbPdvOeC2ZIlHMo", - "type": "text" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [] - }, - "url": { - "raw": "http://localhost/local/laminas/public/user/refresh", - "protocol": "http", - "host": [ - "localhost" - ], - "path": [ - "local", - "laminas", - "public", - "user", - "refresh" - ] - } - }, - "response": [] - } - ] -} diff --git a/src/Factory/Installer/InstallFactory.php b/src/Factory/Installer/InstallFactory.php index f11885c..d1cc23a 100644 --- a/src/Factory/Installer/InstallFactory.php +++ b/src/Factory/Installer/InstallFactory.php @@ -4,7 +4,6 @@ use Interop\Container\ContainerInterface; use Laminas\Db\Adapter\AdapterInterface; -use Laminas\Hydrator\ReflectionHydrator; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; diff --git a/src/Factory/Repository/PermissionRepositoryFactory.php b/src/Factory/Repository/PermissionRepositoryFactory.php index 145c9ad..e9d2cab 100644 --- a/src/Factory/Repository/PermissionRepositoryFactory.php +++ b/src/Factory/Repository/PermissionRepositoryFactory.php @@ -29,9 +29,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o return new PermissionRepository( $container->get(AdapterInterface::class), new ReflectionHydrator(), - new Resource('', '','','', ''), - new Role('', '','',''), - new Page('', '','','','','','','','') + new Resource('', '', '', '', ''), + new Role('', '', '', ''), + new Page('', '', '', '', '', '', '', '', '') ); } } \ No newline at end of file diff --git a/src/Factory/Repository/RoleRepositoryFactory.php b/src/Factory/Repository/RoleRepositoryFactory.php index f55636f..31343c7 100644 --- a/src/Factory/Repository/RoleRepositoryFactory.php +++ b/src/Factory/Repository/RoleRepositoryFactory.php @@ -8,8 +8,8 @@ use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; -use User\Model\Role\Role; use User\Model\Role\Account; +use User\Model\Role\Role; use User\Repository\RoleRepository; class RoleRepositoryFactory implements FactoryInterface diff --git a/src/Model/Account/Account.php b/src/Model/Account/Account.php index 808221c..46a5570 100644 --- a/src/Model/Account/Account.php +++ b/src/Model/Account/Account.php @@ -4,12 +4,12 @@ class Account { - private $id; - private string $name; - private string $identity; - private string $email; - private string $mobile; - private $status; + private $id; + private string $name; + private ?string $identity; + private ?string $email; + private ?string $mobile; + private $status; public function __construct( $name, @@ -22,7 +22,7 @@ public function __construct( $this->name = $name; $this->identity = $identity; $this->email = $email; - $this->mobile = $mobile; + $this->mobile = $mobile; $this->status = $status; $this->id = $id; } @@ -62,7 +62,7 @@ public function getEmail(): string /** * @return string */ - public function getMobile(): string + public function getMobile(): ?string { return $this->mobile; } diff --git a/src/Model/Permission/Page.php b/src/Model/Permission/Page.php index 00cc235..652b30a 100644 --- a/src/Model/Permission/Page.php +++ b/src/Model/Permission/Page.php @@ -72,9 +72,6 @@ public function getModule(): string } - - - /** * @return string */ diff --git a/src/Repository/AccountRepository.php b/src/Repository/AccountRepository.php index 77f4629..3feba93 100644 --- a/src/Repository/AccountRepository.php +++ b/src/Repository/AccountRepository.php @@ -22,6 +22,7 @@ class AccountRepository implements AccountRepositoryInterface { /** * Account Table name + * * @var string */ private string $tableAccount = 'account'; diff --git a/src/Repository/ProfileRepository.php b/src/Repository/ProfileRepository.php index b0f5d22..6bdb567 100644 --- a/src/Repository/ProfileRepository.php +++ b/src/Repository/ProfileRepository.php @@ -10,6 +10,7 @@ class ProfileRepository implements AccountRoleRepositoryInterface { /** * Profile Table name + * * @var string */ private string $tableProfile = 'profile'; diff --git a/src/Repository/RoleRepository.php b/src/Repository/RoleRepository.php index 8fc22a0..fc33ddc 100644 --- a/src/Repository/RoleRepository.php +++ b/src/Repository/RoleRepository.php @@ -2,6 +2,7 @@ namespace User\Repository; +use InvalidArgumentException; use Laminas\Db\Adapter\AdapterInterface; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\ResultSet\HydratingResultSet; @@ -10,10 +11,9 @@ use Laminas\Db\Sql\Sql; use Laminas\Db\Sql\Update; use Laminas\Hydrator\HydratorInterface; -use User\Model\Role\Role; -use User\Model\Role\Account; use RuntimeException; -use InvalidArgumentException; +use User\Model\Role\Account; +use User\Model\Role\Role; class RoleRepository implements RoleRepositoryInterface { diff --git a/src/Repository/RoleRepositoryInterface.php b/src/Repository/RoleRepositoryInterface.php index 2d26cd6..b67ada2 100644 --- a/src/Repository/RoleRepositoryInterface.php +++ b/src/Repository/RoleRepositoryInterface.php @@ -21,5 +21,5 @@ public function getUserRole($userId, $section = ''): HydratingResultSet; public function addUserRole(int $userId, string $roleName, string $section = 'api'): void; - public function deleteUserRole(int $userId, string $roleName) : void; + public function deleteUserRole(int $userId, string $roleName): void; } \ No newline at end of file diff --git a/src/Service/AccountService.php b/src/Service/AccountService.php index caab64d..3942094 100644 --- a/src/Service/AccountService.php +++ b/src/Service/AccountService.php @@ -195,7 +195,7 @@ public function addAccount($params): array $account = $this->canonizeAccount($account); // Set user roles - $this->roleService->addDefaultRoles((int) $account['id']); + $this->roleService->addDefaultRoles((int)$account['id']); return $account; } diff --git a/src/Service/PermissionService.php b/src/Service/PermissionService.php index 96f59cc..8e5c495 100644 --- a/src/Service/PermissionService.php +++ b/src/Service/PermissionService.php @@ -14,14 +14,14 @@ class PermissionService implements ServiceInterface /** * @param PermissionRepositoryInterface $permissionRepository - * @param CacheService $cacheService + * @param CacheService $cacheService */ public function __construct( PermissionRepositoryInterface $permissionRepository, CacheService $cacheService ) { $this->permissionRepository = $permissionRepository; - $this->cacheService = $cacheService; + $this->cacheService = $cacheService; } } \ No newline at end of file diff --git a/src/Validator/MobileValidator.php b/src/Validator/MobileValidator.php index 40a24ba..cc7bce0 100644 --- a/src/Validator/MobileValidator.php +++ b/src/Validator/MobileValidator.php @@ -2,9 +2,9 @@ namespace User\Validator; +use Laminas\I18n\Validator\PhoneNumber; use Laminas\Validator\AbstractValidator; use User\Service\AccountService; -use Laminas\I18n\Validator\PhoneNumber; class MobileValidator extends AbstractValidator {