Package Data | |
---|---|
Maintainer Username: | LONGMAN |
Maintainer Contact: | akalongman@gmail.com (Avtandil Kikabidze aka LONGMAN) |
Package Create Date: | 2017-08-17 |
Package Last Update: | 2017-08-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:04:04 |
Package Statistics | |
---|---|
Total Downloads: | 3,349 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Dummy (without database) user authorization for Laravel 5.x
Install this package through Composer.
Edit your project's composer.json
file to require longman/laravel-dummyuser
Create composer.json file:
{
"name": "yourproject/yourproject",
"type": "project",
"require": {
"longman/laravel-dummyuser": "~1.0"
}
}
And run composer update
Or run a command in your command line:
composer require longman/laravel-dummyuser
After updating composer, add the DummyUserServiceProvider to the providers array in config/app.php
Longman\LaravelDummyUser\DummyUserServiceProvider::class,
In the config/auth.php
file you should add dummy guard in the guards
array:
'guards' => [
. . .
'dummy' => [
'driver' => 'session',
'provider' => 'dummy',
],
]
and provider in the providers
array
'providers' => [
. . .
'dummy' => [
'driver' => 'dummy',
'lifetime' => 3600, // Cache lifetime in minutes
],
]
You can specify default guard dummy
in the config/auth.php
file (defaults
array) and use just Auth::
calls, or use Auth::guard('dummy')
, like Auth::guard('dummy')->login($user)
For authenticating users, you need some unique identifier. You can use remote id or something like md5('some-unique-mail@mail.com')
In User model you need to add id
in fillable array. And if you use string id
also add protected $keyType = 'string';
field.
Usage example:
<?php
// get some user data from Restful service
$user_data = get_user_data_from_service();
$email = $user_data['email'];
$user = new User(['id' => md5($email), 'name' => $user_data['name'], ...]);
// Log in user
Auth::login($user);
write tests
If you like living on the edge, please report any bugs you find on the laravel-dummyuser issues page.
Pull requests are welcome. See CONTRIBUTING.md for information.
Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.