{"id":15282282,"url":"https://github.com/yiisolutions/yii2-user-module","last_synced_at":"2026-05-04T06:36:15.908Z","repository":{"id":57087263,"uuid":"76487834","full_name":"yiisolutions/yii2-user-module","owner":"yiisolutions","description":"Yii2 user module","archived":false,"fork":false,"pushed_at":"2016-12-20T20:36:04.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T21:27:53.784Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-14T18:53:26.000Z","updated_at":"2016-12-14T20:27:53.000Z","dependencies_parsed_at":"2022-08-25T00:50:49.060Z","dependency_job_id":null,"html_url":"https://github.com/yiisolutions/yii2-user-module","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisolutions%2Fyii2-user-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisolutions%2Fyii2-user-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisolutions%2Fyii2-user-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisolutions%2Fyii2-user-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisolutions","download_url":"https://codeload.github.com/yiisolutions/yii2-user-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245120455,"owners_count":20563914,"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-09-30T14:24:58.003Z","updated_at":"2026-05-04T06:36:15.843Z","avatar_url":"https://github.com/yiisolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-user-module\n\n[![Latest Stable Version](https://poser.pugx.org/yiisolutions/yii2-user-module/v/stable)](https://packagist.org/packages/yiisolutions/yii2-user-module)\n[![Total Downloads](https://poser.pugx.org/yiisolutions/yii2-user-module/downloads)](https://packagist.org/packages/yiisolutions/yii2-user-module)\n[![Build Status](https://travis-ci.org/yiisolutions/yii2-user-module.svg?branch=master)](https://travis-ci.org/yiisolutions/yii2-user-module)\n[![codecov](https://codecov.io/gh/yiisolutions/yii2-user-module/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisolutions/yii2-user-module)\n[![License](https://poser.pugx.org/yiisolutions/yii2-user-module/license)](https://packagist.org/packages/yiisolutions/yii2-user-module)\n\nYii2 user module.\n\n## Installation\n\nUse composer\n\n```bash\ncomposer require \"yiisolutions/yii2-user-module: @dev\"\n```\n\nor add to `composer.json`\n\n```json\n{\n  \"require\": {\n    \"yiisolutions/yii2-user-module\": \"@dev\"\n  }\n}\n```\n\n## Configuration\n\nFor enable user module edit your configuration\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    'modules' =\u003e [\n        // ...\n        'user' =\u003e [\n            'class' =\u003e 'yiisolutions\\user\\Module',\n        ],\n        // ...\n    ],\n    // ...\n];\n```\n\n## Console commands\n\nThis module provider console commands for manager users\n\n* `user/commands/create` - create new user\n* `user/commands/truncate` - clear user table\n\n## Web controller actions\n\nThis module provide web controller actions:\n\n* `yiisolutions\\user\\actions\\LoginAction` - for user login\n* `yiisolutions\\user\\actions\\LogoutAction` - for logout \n* `yiisolutions\\user\\actions\\SignUpAction` - for sign up new user\n\nFor enable these actions use controller `actions()` method\n\n```php\n\u003c?php\n\nnamespace app\\controllers;\n\nuse Yii;\nuse yii\\web\\Controller;\nuse yii\\web\\IdentityInterface;\nuse yiisolutions\\user\\actions\\LoginAction;\nuse yiisolutions\\user\\actions\\LogoutAction;\nuse yiisolutions\\user\\actions\\SignUpAction;\nuse yiisolutions\\user\\events\\LoginEvent;\nuse yiisolutions\\user\\models\\LoginFormInterface;\n\nclass AccountController extends Controller\n{\n    public function actions()\n    {\n        return [\n            'login' =\u003e [\n                'class' =\u003e LoginAction::className(), \n                'view' =\u003e 'login',  // use @app/views/account/login.php view file\n                'on loginSuccess' =\u003e [$this, 'onLoginSuccess'], // alternative success callback (default redirect to back)\n                'on loginFailed' =\u003e [$this, 'onLoginFailed'], // do something when login failed (for example, logging)\n            ],\n            'logout' =\u003e [\n                'class' =\u003e LogoutAction::className(),\n            ],\n            'sign-up' =\u003e [\n                'class' =\u003e SignUpAction::className(),\n            ],\n        ];        \n    }    \n    \n    /**\n     * Run when login success.\n     */\n    public function onLoginSuccess(LoginEvent $event, LoginFormInterface $model)\n    {\n        // do something ...\n        $username = $model-\u003egetUserIdentity()-\u003eusername;\n        Yii::info(\"User '{$username}' logged in\");\n        \n        // override default action return value\n        $event-\u003ereturn = $this-\u003eredirect('/profile');\n    }\n    \n    /**\n     * Run when login error. \n     */\n    public function onLoginFailed(LoginEvent $event, LoginFormInterface $model)\n    {\n        // do something ...\n        $user = $model-\u003egetUserIdentity();\n        if ($user instanceof IdentityInterface) {\n            // do something, when exists user fail login ...\n        } else {\n            // do something, else ...\n        }\n        \n        $user = $model-\u003egetUserIdentity();\n        if ($user) {\n            // send email notification, increment attempt counter etc ...\n        }\n    }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisolutions%2Fyii2-user-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisolutions%2Fyii2-user-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisolutions%2Fyii2-user-module/lists"}