Download the PHP package autn/gcl-users without Composer
On this page you can find all versions of the php package autn/gcl-users. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gcl-users
Laravel Users Module
This module is use JWTAuth and ENTRUST libraries
- https://github.com/tymondesigns/jwt-auth (JSON Web Token)
- https://github.com/Zizaco/entrust (Role-based Permissions)
- https://github.com/php-soft/laravel-users (Users manager)
1. Installation
Install via composer - edit your composer.json
to require the package.
Version Compatibility
GclUsers | Laravel |
---|---|
1.x | 5.1.x |
2.x | 5.2.x |
Then run composer update
in your terminal to pull it in.
Once this has finished, you will need to add the service provider to the providers
array in your app.php
config as follows:
Next, also in the app.php
config file, under the aliases
array, you may want to add facades.
You will want to publish the config using the following command:
Don't forget to set a secret key in the jwt config file!
I have included a helper command to generate a key as follows:
this will generate a new random key, which will be used to sign your tokens.
2. Migration and Seeding
Now generate the migration:
It will generate the <timestamp>_entrust_setup_tables.php
migration. You may now run it with the artisan migrate command:
Running Seeders with command:
Note: Run seeders after use UserTrait
in your existing App\User
model, follow 3.2 below
3. Usage
3.1. Authenticate with JSON Web Token
You need to change class App\User
to inherit from Gcl\GclUsers\Models\User
as follows:
Remove middlewares in app/Http/Kernel.php
\App\Http\Middleware\EncryptCookies::class
\App\Http\Middleware\VerifyCsrfToken::class
Add route middlewares in app/Http/Kernel.php
Add routes in app/Http/routes.php
Note: You can add this to your middleware groups api
Apache seems to discard the Authorization header if it is not a base64 encoded user/pass combo. So to fix this you can add the following to your apache config
Alternatively you can include the token via a query string
3.2. Role-based Permissions
Use the UserTrait
trait in your existing App\User
model. For example:
Create Role
and Permission
follows
Now we can check for roles and permissions simply by doing:
Both hasRole()
and can()
can receive an array of roles & permissions to check:
3.3 Forgot password
To send mail forgot password,
-
You need to add address and name of sender in
config\mail.php
as follows: - You need to create email view:
Create
password.blade.php
file in folderresources\views\emails
with contents as follows:
You can change contents of this view for your using.
By other way, you can use other view and config password.email
in config\auth.php
:
3.4 Middlewares
Gcl\GclUsers\Middleware\RoutePermission
This middleware is used to check permission for a route dynamic by database.
Add route middlewares in app/Http/Kernel.php
Usage
Require permission for a route as follows
Gcl\GclUsers\Middleware\Validate
This middleware is used to check validate for fields on different applications which use this package.
Add route middlewares in app/Http/Kernel.php
Usage
With App\Http\Validators\UserValidate
, it's class which you need to declare in route. This class is used to declare rules to validate.
You can also use other class to declare rules for validate in your application but It have to implements Gcl\GclUsers\Contracts\Validator
class.
For example, I declared rules in App\Http\Validators\UserValidate
class as follows:
Here, you will declare fields that you want to validate them in rules()
function. And You can also custom validator fields that you want by declare them in boot()
function.
All versions of gcl-users with dependencies
laravel/framework Version 5.2.*
php-soft/laravel-array-view Version 1.1.4
tymon/jwt-auth Version 0.5.*
zizaco/entrust Version dev-laravel-5
doctrine/dbal Version ^2.5
baum/baum Version ~1.1