-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/Providers/NovaWithoutAuthenticationServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Laravel\Nova\Nova; | ||
|
||
class NovaWithoutAuthenticationServiceProvider extends NovaServiceProvider | ||
{ | ||
/** | ||
* Register the Nova routes. | ||
* | ||
* @return void | ||
*/ | ||
protected function routes() | ||
{ | ||
config([ | ||
'nova.routes.login' => '/login', | ||
'nova.routes.logout' => '/logout', | ||
]); | ||
|
||
Nova::routes() | ||
->withoutAuthenticationRoutes() | ||
->withPasswordResetRoutes() | ||
->register(fortify: false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ | |
'nova', | ||
Authenticate::class, | ||
Authorize::class, | ||
// 'nova.verified', | ||
], | ||
|
||
/* | ||
|
46 changes: 46 additions & 0 deletions
46
database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use Laravel\Fortify\Fortify; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->text('two_factor_secret') | ||
->after('password') | ||
->nullable(); | ||
|
||
$table->text('two_factor_recovery_codes') | ||
->after('two_factor_secret') | ||
->nullable(); | ||
|
||
if (Fortify::confirmsTwoFactorAuthentication()) { | ||
$table->timestamp('two_factor_confirmed_at') | ||
->after('two_factor_recovery_codes') | ||
->nullable(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn(array_merge([ | ||
'two_factor_secret', | ||
'two_factor_recovery_codes', | ||
], Fortify::confirmsTwoFactorAuthentication() ? [ | ||
'two_factor_confirmed_at', | ||
] : [])); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,16 @@ | |
|
||
namespace Laravel\Nova\Tests\Browser; | ||
|
||
use Database\Factories\UserFactory; | ||
use Laravel\Dusk\Browser; | ||
use Laravel\Nova\Nova; | ||
use Laravel\Nova\Testing\Browser\Components\SidebarComponent; | ||
use Laravel\Nova\Testing\Browser\Pages\Dashboard; | ||
use Laravel\Nova\Testing\Browser\Pages\Login; | ||
use Laravel\Nova\Tests\DuskTestCase; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
#[Group('auth')] | ||
class AuthenticatesUserTest extends DuskTestCase | ||
{ | ||
#[DataProvider('intendedUrlDataProvider')] | ||
|
@@ -24,7 +25,8 @@ public function test_it_redirect_to_intended_url_after_login($targetUrl, $expect | |
->type('email', '[email protected]') | ||
->type('password', 'password') | ||
->clickAndWaitForReload('button[type="submit"]') | ||
->assertPathIs(Nova::url($expectedUrl)); | ||
->assertPathIs(Nova::url($expectedUrl)) | ||
->assertAuthenticated(); | ||
|
||
$browser->blank(); | ||
}); | ||
|
@@ -112,25 +114,6 @@ public function test_redirect_outside_of_nova_after_login() | |
}); | ||
} | ||
|
||
public function test_it_redirect_to_login_after_password_reset() | ||
{ | ||
$this->browse(function (Browser $browser) { | ||
$user = UserFactory::new()->create(); | ||
|
||
$browser->logout() | ||
->assertGuest() | ||
->visit(Nova::url('password/reset')) | ||
->waitForText('Forgot your password?') | ||
->type('input[id="email"]', $user->email) | ||
->click('button[type="submit"]') | ||
->waitForText(__('passwords.sent')) | ||
->pause(5000) | ||
->waitForLocation(Nova::url('login')); | ||
|
||
$browser->blank(); | ||
}); | ||
} | ||
|
||
public static function intendedUrlDataProvider() | ||
{ | ||
yield ['/resources/users/3', '/resources/users/3']; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Laravel\Nova\Tests\Browser; | ||
|
||
use App\Providers\NovaServiceProvider; | ||
use App\Providers\NovaWithoutAuthenticationServiceProvider; | ||
use Database\Factories\UserFactory; | ||
use Laravel\Dusk\Browser; | ||
use Laravel\Nova\Nova; | ||
use Laravel\Nova\Tests\DuskTestCase; | ||
use Orchestra\Testbench\Attributes\WithConfig; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
#[Group('auth')] | ||
#[WithConfig('mail.default', 'log')] | ||
class CustomForgotUserPasswordTest extends DuskTestCase | ||
{ | ||
/** | ||
* Get package providers. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* @return array<int, class-string> | ||
*/ | ||
protected function getPackageProviders($app) | ||
{ | ||
return collect(parent::getPackageProviders($app)) | ||
->replace([ | ||
NovaServiceProvider::class => NovaWithoutAuthenticationServiceProvider::class, | ||
])->all(); | ||
} | ||
|
||
public function test_it_redirect_to_login_after_password_reset() | ||
{ | ||
$this->beforeServingApplication(function ($app, $config) { | ||
$config->set('mail.default', 'log'); | ||
}); | ||
|
||
$this->browse(function (Browser $browser) { | ||
$user = UserFactory::new()->create(); | ||
|
||
$browser->logout() | ||
->assertGuest() | ||
->visit(Nova::url('password/reset')) | ||
->waitForText('Forgot your password?') | ||
->type('input[id="email"]', $user->email) | ||
->clickAndWaitForReload('button[type="submit"]', 40) | ||
->assertPathIs('/login'); | ||
|
||
$browser->blank(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.