{"id":21569294,"url":"https://github.com/mehrancodes/laravel-user-verification","last_synced_at":"2025-04-10T14:06:40.175Z","repository":{"id":62533410,"uuid":"106815538","full_name":"mehrancodes/laravel-user-verification","owner":"mehrancodes","description":"A simple package to verify the users by token and code number","archived":false,"fork":false,"pushed_at":"2017-10-14T19:05:25.000Z","size":12,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T20:41:31.005Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehrancodes.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":"2017-10-13T11:23:11.000Z","updated_at":"2023-09-05T06:19:36.000Z","dependencies_parsed_at":"2022-11-02T15:00:22.642Z","dependency_job_id":null,"html_url":"https://github.com/mehrancodes/laravel-user-verification","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrancodes%2Flaravel-user-verification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrancodes%2Flaravel-user-verification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrancodes%2Flaravel-user-verification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrancodes%2Flaravel-user-verification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehrancodes","download_url":"https://codeload.github.com/mehrancodes/laravel-user-verification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248231898,"owners_count":21069423,"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-11-24T11:09:04.562Z","updated_at":"2025-04-10T14:06:40.155Z","avatar_url":"https://github.com/mehrancodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-user-verification\nA simple package to activate the users by token and code number.\n\nThis package allows you to verify the users either by token to be sent by email and code number for SMS.\n\n## Installation\nThis package can be used in Laravel 5.4 or higher.\n\nYou can install the package via composer:\n```bash\ncomposer require rasulian/laravel-user-verification\n```\n\nIn Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:\n```php\n'providers' =\u003e [\n    // ...\n    Rasulian\\Verification\\VerificationServiceProvider::class,\n];\n```\n\nYou may add the following aliases to your config/app.php:\n```php\n'aliases' =\u003e [\n    // ...\n    'Verification' =\u003e Rasulian\\UserVerification\\Facades\\Verification::class,\n```\n\nPublish the package config and database migration file by running the following command:\n```bash\nphp artisan vendor:publish --provider=\"Rasulian\\Verification\\VerificationServiceProvider::class\"\n```\n\n## Configuration\n\n### Migration\nThe table representing the user model must be updated with the `verified` column. This update will be performed by the migration included with this package.\n\n**Please make sure that you don't have the this column on your user table.**\n\nIf your user table name is not `users`, you may change that in the `config/verification.php`.\n\nNow you can migrate the normal way you do:\n```bash\nphp artisan migrate\n```\n\n### Middleware\nThis package provides an optional middleware throwing `UserVerifiedMiddleware`.\nPlease refer to the [Laravel Documentation](https://laravel.com/docs/master/errors#the-exception-handler) to learn more\nabout how to work with the exception handler.\n\nTo register the default middleware add the following lines to the `$routeMiddleware` array within the `app/Http/Kernel.php` file:\n```php\nprotected $routeMiddleware = [\n    'user.verified' =\u003e \\Rasulian\\UserVerification\\Middlewares\\UserVerifiedMiddleware::class,\n];\n```\n\nYou may use this middleware for the routes that needs the user's email or phone number be verified:\n```php\nRoute::middleware('auth', 'user.verified')-\u003egroup(function () {\n    // Routes here\n});\n```\n\n### Errors\nThis package throws several exception. you may use `try\\catch` statement or the Laravel exception handler.\n\n* `UserIsVerifiedException` The given user is already verified\n* `UserNotVerifiedException` The given user is not verified\n* `VerifyTokenMismatchException` The given token is wrong or not available\n* `VerifyCodeMismatchException` The given code is wrong or not available\n\n## Usage\n\n### Route\nBy default this package provide one route to verify the user by token.\n```php\nRoute::get('user/verification/{token}', 'App\\Http\\Controllers\\Auth\\RegisterController@verifyUser')\n    -\u003ename('user.verify');\n```\n\n#### Overriding package route\nTo define your own custom routes, put the package service provider call before the `RouteServiceProvider` call in the `config/app.php` file.\n```php\n/*\n * Package Service Providers...\n */\nRasulian\\UserVerification\\VerificationServiceProvider::class,\n\n/*\n * Application Service Providers...\n */\nApp\\Providers\\RouteServiceProvider::class,\n```\nThen, add your custom route in your route file.\n\n### Facade\nThe package offers a facade Verification::.\n\n### verification Config file\nAfter publishing the package config, it will be located at the `config` directory. You are free to change the table name\nfor the `user` and the `user_verifications` which represents the fields for storing the token and code.\n\n```php\n\u003c?php\n\nreturn [\n    'table_names' =\u003e [\n        'users' =\u003e 'users',\n        'user_verifications' =\u003e 'user_verifications'\n    ],\n\n    /**\n     * number of hours that needs to pass before\n     * we generate a new token\\code but only if user request it.\n     */\n    'generate_after' =\u003e 24\n];\n```\n\n### How to use the package\nThis package is written as simple as possible.\nIt creates a token and code for the user and verifies the user either by token or code.\n\nHere is a sample on how to generate a token, send it as an email and verify it.\n\nEdit the `App\\Http\\Auth\\RegisterController` file:\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers\\Auth;\n\nuse App\\Mail\\Welcome;\nuse App\\Http\\Controllers\\Controller;\nuse Illuminate\\Http\\Request;\nuse Mail;\nuse Rasulian\\UserVerification\\Facades\\Verification;\n\nclass RegisterController extends Controller\n{\n    //\n    // Code\n    //\n\n    /**\n     * Create a new controller instance.\n     *\n     * @return void\n     */\n    public function __construct()\n    {\n        $this-\u003emiddleware('guest', ['except' =\u003e 'verifyUser']);\n    }\n\n    //\n    // Code\n    //\n\n    /**\n     * The user has been registered.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  mixed  $user\n     * @return mixed\n     */\n    protected function registered(Request $request, $user)\n    {\n        $token = Verification::getVerificationToken($user);\n        $url = route('user.verify', $token);\n        Mail::to($user-\u003eemail)-\u003esend(new Welcome($url));\n\n        return redirect('/home')-\u003ewith('success', 'Registered. Verify your email!');\n    }\n\n    public function verifyUser($token)\n    {\n        $user = Verification::verifyUserByToken($token);\n\n        if (auth()-\u003eguest())\n            auth()-\u003elogin($user);\n\n        return redirect('/home')-\u003ewith('success', 'Your email verified successfully!');\n    }\n}\n```\n\nHere we use the `registered` method to create token and send it,\nwhich will overrides `\\Illuminate\\Foundation\\Auth\\RegistersUsers@registered` method.\nWe get a token for the given user, make it as a url and send it as an email.\n\nIf the user clicks on the link, the `verifyUser` method will be executed.\nHere we just verify the user by the given token.\n\n**Please make sure that you add the `verifyUser` to the `except` array of the `guest` middleware in the constructor.**\n\n#### Relaunch the process\nIf you want to regenerate and resend the verification token, you can do this with the `getVerificationToken` method.\n\nThe generate method will generate a new token for the given user and change the `verified` column to `false`.\n\n## CONTRIBUTE\nFeel free to comment, contribute and help. 1 PR = 1 feature.\n\n## LICENSE\nLaravel User Verification is licensed under [The MIT License (MIT)](https://github.com/mehranrasulian/laravel-user-verification/blob/master/LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehrancodes%2Flaravel-user-verification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehrancodes%2Flaravel-user-verification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehrancodes%2Flaravel-user-verification/lists"}