atomjoy / webi-mini
Laravel web rest api authentication library.
v1.0.0
2023-03-05 12:07 UTC
Requires
- php: ^8.1
- laravel/framework: ^10.0
This package is not auto-updated.
Last update: 2024-12-23 20:16:00 UTC
README
Laravel rest api authentication.
Install (Laravel 10, Php 8.1)
First set your .env variables (mysql, smtp) and then
composer require atomjoy/webi-mini
User model
// app/Models/User.php <?php namespace App\Models; use Webi\Models\WebiUser; class User extends WebiUser { function __construct(array $attributes = []) { parent::__construct($attributes); $this->mergeFillable([ // 'mobile', 'website' ]); $this->mergeCasts([ // 'role' => UserRole::class, // 'status' => StatusEnum::class, // 'email_verified_at' => 'datetime:Y-m-d H:i:s', ]); // $this->hidden[] = 'secret_hash'; } protected $dispatchesEvents = [ // 'saved' => UserSaved::class, // 'deleted' => UserDeleted::class, ]; }
Create login page
// routes/web.php Route::get('/login', function() { return 'My login page'; // return view('vue'); })->name('login');
Create activation page
// routes/web.php use Webi\Http\Controllers\WebiActivate; // Create your own activation page for Vue, Laravel Route::get('/activate/{id}/{code}', [YourActivationController::class, 'index'])->middleware(['webi-locale']); // Or for tests use json controller from Webi\Http\Controllers\WebiActivate.php Route::get('/activate/{id}/{code}', [WebiActivate::class, 'index'])->middleware(['webi-locale']);
Copy translations to app lang (for tests only)
php artisan lang:publish php artisan vendor:publish --tag=webi-lang-en --force php artisan vendor:publish --tag=webi-lang-pl --force
Create db tables
# Create tables php artisan migrate # Refresh tables php artisan migrate:fresh # Seed data (optional) php artisan db:seed --class=WebiSeeder
Run application
php artisan serve
Testing
Tests readme file location
tests/README.md
Settings (optional)
Customize
# Edit email blade themes php artisan vendor:publish --tag=webi-email # Edit lang translations php artisan vendor:publish --tag=webi-lang # Edit config php artisan vendor:publish --tag=webi-config # Override config php artisan vendor:publish --tag=webi-config --force # Add the image logo to your mail php artisan vendor:publish --tag=webi-public # Provider php artisan vendor:publish --provider="Webi\WebiServiceProvider.php"
Tables seeder
php artisan db:seed --class=WebiSeeder
Update classes
composer update composer dump-autoload -o composer update --no-dev
Web API Requests
Send requests as json. Response as json: {'message', "user"}. For more go to: src/Http/Requests and src\Http\Controllers directories or to routes file routes/web.php.
/web/api/login
Method: POST
Params: 'email', 'password', 'remember_me' Data: {'message', "user"}
/web/api/register
Method: POST
Params: 'name', 'email', 'password', 'password_confirmation' Data: {'message', 'created'}
/web/api/reset
Method: POST
Params: 'email' Data: {'message'}
/web/api/activate/{id}/{code}
Method: GET
Params: 'id', 'code' Data: {'message'}
/web/api/logout
Method: GET
Params: without params
Data: {'message'}
/web/api/locale/{locale}
Method: GET
Params: 'locale' Data: {'message', 'locale'}
/web/api/csrf
Method: GET
Params: without params Data: {'message', 'counter', 'locale'}
/web/api/logged
Method: GET
Params: without params Data: {'message', 'locale', "user"}
/web/api/change-password
Method: POST Auth: true
Params: 'password_current', 'password', 'password_confirmation' Data: {'message'}
/web/api/test/user, /web/api/test/worker, /web/api/test/admin
Method: GET Auth: true
Params: without params Data: {'message', "user", 'ip'}