Add fallback provider
This commit is contained in:
parent
1fb212b553
commit
26c81eb567
|
@ -3,10 +3,14 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Zoomyboy\LaravelNami\NamiUser as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
||||
|
||||
use HasFactory;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\User;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|
@ -37,7 +39,8 @@ return [
|
|||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'nami'
|
||||
'driver' => 'nami',
|
||||
'other_providers' => ['database'],
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
@ -65,15 +68,10 @@ return [
|
|||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'nami',
|
||||
'model' => \App\User::class
|
||||
'database' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
|
||||
protected $model = User::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('email');
|
||||
$table->string('password');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit 6d6aa60363554c7f049ff91691302c7ef5c92d79
|
||||
Subproject commit f30a1d19bf4296797521e6eeeda49853483b417b
|
|
@ -11,7 +11,7 @@ use Tests\TestCase;
|
|||
use Zoomyboy\LaravelNami\Authentication\NamiGuard;
|
||||
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
class NamiLoginTest extends TestCase
|
||||
{
|
||||
|
||||
use RefreshDatabase;
|
||||
|
@ -31,6 +31,7 @@ class LoginTest extends TestCase
|
|||
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
|
||||
|
@ -54,11 +55,13 @@ class LoginTest extends TestCase
|
|||
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
auth()->logout();
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
|
||||
|
@ -77,11 +80,13 @@ class LoginTest extends TestCase
|
|||
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
app(NamiGuard::class)->setUser(null);
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
|
||||
|
@ -97,6 +102,7 @@ class LoginTest extends TestCase
|
|||
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
])->assertRedirect('/');
|
||||
|
||||
|
@ -113,6 +119,7 @@ class LoginTest extends TestCase
|
|||
|
||||
$this->post('/login', [
|
||||
'mglnr' => 123,
|
||||
'provider' => 'nami',
|
||||
'password' => 'secret'
|
||||
])->assertRedirect('/');
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Setting\GeneralSettings;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
use Zoomyboy\LaravelNami\Authentication\NamiGuard;
|
||||
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||
|
||||
class UserLoginTest extends TestCase
|
||||
{
|
||||
|
||||
use RefreshDatabase;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testItCanLoginWithUserAccount(): void
|
||||
{
|
||||
$this->init();
|
||||
$this->withoutExceptionHandling();
|
||||
$user = User::factory()->create(['email' => 'mail@example.com', 'password' => Hash::make('secret')]);
|
||||
|
||||
$this->post('/login', [
|
||||
'email' => 'mail@example.com',
|
||||
'provider' => 'database',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
|
||||
$key = session()->get('auth_key');
|
||||
$cache = Cache::get("namiauth-{$key}");
|
||||
$this->assertEquals($user->id, data_get($cache, 'id'));
|
||||
$this->assertTrue(auth()->check());
|
||||
}
|
||||
|
||||
public function testItThrowsExceptionWhenLoginFailed(): void
|
||||
{
|
||||
$this->init();
|
||||
$user = User::factory()->create(['email' => 'mail@example.com', 'password' => Hash::make('secret')]);
|
||||
|
||||
$this->post('/login', [
|
||||
'email' => 'mail@example.com',
|
||||
'provider' => 'database',
|
||||
'password' => 'wrong'
|
||||
])->assertRedirect('/');
|
||||
|
||||
$this->assertFalse(auth()->check());
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ abstract class TestCase extends BaseTestCase
|
|||
app(FakeBackend::class)
|
||||
->fakeLogin('123')
|
||||
->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]);
|
||||
auth()->login([
|
||||
auth()->loginNami([
|
||||
'mglnr' => 123,
|
||||
'password' => 'secret',
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue