PHPackages                             smartins/user-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. smartins/user-module

ActiveLaravel-module[Authentication &amp; Authorization](/categories/authentication)

smartins/user-module
====================

09PHP

Since Dec 6Pushed 6y agoCompare

[ Source](https://github.com/sfelix-martins/user-module)[ Packagist](https://packagist.org/packages/smartins/user-module)[ RSS](/packages/smartins-user-module/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

User Module
===========

[](#user-module)

This module is a skeleton to handle with users in your API with things generally required. It's has endpoints to register, auth (default and facebook), password resets and confirmation email.

The module was made to works with [Laravel Modules](https://github.com/nWidart/laravel-modules) package. A great package to organize your Laravel projects structure in `modules` instead keep your files into your `app` folder.

Features
--------

[](#features)

- Register Users
- OAuth 2 Authentication (Default and Facebook) using [Laravel Passport](https://laravel.com/docs/5.5/passport).
- Reset Passwords
    - You can resets password on **browser** using routes:
        - GET : `/password/reset` to show link request form
        - POST : `/password/email` to send reset link email
        - GET : `/password/reset/{token}` to show reset form
        - POST : `/password/reset` to reset password
    - Or using the API endpoints
- Confirm Account

Used Packages
-------------

[](#used-packages)

- [Laravel Passport](https://laravel.com/docs/5.5/passport)
- [Laravel Socialite](https://github.com/laravel/socialite)
- [Passport Social Grant](https://github.com/adaojunior/passport-social-grant)
- [Laravel Cors](https://github.com/barryvdh/laravel-cors)

Endpoints
---------

[](#endpoints)

- `POST`: /v1/users - Create users
- `POST`: /v1/oauth/token - Default login and Facebook Login
- `GET` : /v1/users/{id} - Get one user
- `POST`: /v1/password/email - Sends password reset emails
- `POST`: /v1/password/reset - Resets Passwords
- `GET` : /v1/account/verify/{token} - Confirm email

More details on [Swagger Docs](https://app.swaggerhub.com/apis/sfelix-martins/LaravelRobustAPI/1.0.0#/)

Events
------

[](#events)

- `Illuminate\Auth\Events\Registered` when user is registered
- `Illuminate\Auth\Events\PasswordReset` when resets password

Configuring
-----------

[](#configuring)

#### Prerequisites

[](#prerequisites)

- A [laravel project](https://laravel.com/docs/5.5/)

#### Installing

[](#installing)

- Install the user module on your project:

```
$ composer require smartins/user-module
```

The module must be in `Modules\User` folder of your project

#### Database

[](#database)

**IMPORTANT:** Note that the migrations `create_users_table` and `create_password_resets_table` already exists in your project by default. To module works correctly delete the default migrations to create `users` and `password_resets_table` and use the migrations from User module. You can see the tables structure on `Modules\User\Database\Migrations`

- Publish the module migrations:

```
$ php artisan module:publish-migration User
```

- And run migrations:

```
$ php artisan migrate
```

The migrations to create `users`, `password_resets` and [Laravel Passport](https://laravel.com/docs/5.5/passport) migrations will be executed. Congratulations! You have the database structure to Register, Confirm Account, Login (OAuth2 - Default and Facebook) and Resets Password of your Users!

#### API Authentication (Laravel Passport)

[](#api-authentication-laravel-passport)

The next step is configure the [Laravel Passport](https://laravel.com/docs/5.5/passport)

- Run the `passport:install` command to the encryption keys needed to generate secure access tokens. Copy the "password grant" client which will be used to generate access tokens:

```
$ php artisan passport:install
```

- Next, you should call the `Passport::routes` method within the boot method of your `AuthServiceProvider`. This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens:

```
