{"id":22666897,"url":"https://github.com/piko-framework/user","last_synced_at":"2025-03-29T10:14:51.824Z","repository":{"id":57041565,"uuid":"410247800","full_name":"piko-framework/user","owner":"piko-framework","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-04T14:35:04.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T18:24:24.622Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piko-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T10:54:45.000Z","updated_at":"2022-10-15T19:46:37.000Z","dependencies_parsed_at":"2022-08-24T00:51:11.131Z","dependency_job_id":null,"html_url":"https://github.com/piko-framework/user","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fuser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fuser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fuser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fuser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piko-framework","download_url":"https://codeload.github.com/piko-framework/user/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246168109,"owners_count":20734390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T14:32:13.160Z","updated_at":"2025-03-29T10:14:51.804Z","avatar_url":"https://github.com/piko-framework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Piko User\n\n[![build](https://github.com/piko-framework/user/actions/workflows/php.yml/badge.svg)](https://github.com/piko-framework/user/actions/workflows/php.yml)\n[![Coverage Status](https://coveralls.io/repos/github/piko-framework/user/badge.svg?branch=main)](https://coveralls.io/github/piko-framework/user?branch=main)\n\nA lightweight user session manager to login/logout, check permissions and retrieve user identity between sessions.\n\n# Installation\n\nIt's recommended that you use Composer to install Piko User.\n\n```bash\ncomposer require piko/user\n```\n\n# Usage\n\nBasic exemple:\n\n```php\nrequire 'vendor/autoload.php';\n\nuse Piko\\User;\nuse Piko\\User\\IdentityInterface;\n\n// Define first your user identity class\nclass Identity implements IdentityInterface\n{\n    private static $users = [\n        1 =\u003e 'paul',\n        2 =\u003e 'pierre',\n    ];\n\n    public $id;\n    public $username;\n\n    public static function findIdentity($id)\n    {\n        if (isset(static::$users[$id])) {\n            $user = new static();\n            $user-\u003eid = $id;\n            $user-\u003eusername = static::$users[$id];\n\n            return $user;\n        }\n\n        return null;\n    }\n\n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n}\n\n$user = new User([\n    'identityClass' =\u003e Identity::class,\n    'checkAccess' =\u003e function($id, $permission) {\n        return $id == 1 \u0026\u0026 $permission == 'test';\n    }\n]);\n\n// Login\n\n$user-\u003elogin(Identity::findIdentity(1));\n\nif (!$user-\u003eisGuest()) {\n    echo $user-\u003egetIdentity()-\u003eusername; // paul\n}\n\nif ($user-\u003ecan('test')) {\n    echo 'I can test';\n}\n\n$user-\u003elogout();\n\nif ($user-\u003eisGuest()) {\n    var_dump($user-\u003egetIdentity()); // null\n    echo 'Not Authenticated';\n}\n\nif (!$user-\u003ecan('test')) {\n    echo 'I cannot test';\n}\n\n```\n\nAdvanced example: [See UserTest.php](tests/UserTest.php)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiko-framework%2Fuser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiko-framework%2Fuser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiko-framework%2Fuser/lists"}