Skip to content

Commit

Permalink
formatting and modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 11, 2020
1 parent 290bea7 commit 3ed5e87
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 66 deletions.
6 changes: 3 additions & 3 deletions routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@
->middleware(['auth']);
}

// Password Verification...
Route::get('/user/password/verify', 'VerifyPasswordController@show')
// Password Confirmation...
Route::get('/user/confirm-password', 'ConfirmablePasswordController@show')
->middleware(['auth'])
->name('password.confirm');

Route::post('/user/password/verify', 'VerifyPasswordController@store')
Route::post('/user/confirm-password', 'ConfirmablePasswordController@store')
->middleware(['auth']);

// Two Factor Authentication...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Support\Responsable;

interface VerifyPasswordViewResponse extends Responsable
interface ConfirmPasswordViewResponse extends Responsable
{
//
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Support\Responsable;

interface FailedPasswordVerifyResponse extends Responsable
interface FailedPasswordConfirmationResponse extends Responsable
{
//
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Support\Responsable;

interface PasswordVerifiedResponse extends Responsable
interface PasswordConfirmedResponse extends Responsable
{
//
}
9 changes: 5 additions & 4 deletions src/Fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Fortify;

use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\RegisterViewResponse;
Expand Down Expand Up @@ -138,14 +139,14 @@ public static function verifyEmailView($view)
}

/**
* Specify which view should be used as the password verification prompt.
* Specify which view should be used as the password confirmation prompt.
*
* @param string $view
* @param callable|string $view
* @return void
*/
public static function verifyPasswordView($view)
public static function confirmPasswordView($view)
{
app()->singleton(VerifyPasswordViewResponse::class, function () use ($view) {
app()->singleton(ConfirmPasswordViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
Expand Down
20 changes: 10 additions & 10 deletions src/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse as FailedPasswordConfirmationResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse as FailedPasswordResetLinkRequestResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordResetResponse as FailedPasswordResetResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordVerifyResponse as FailedPasswordVerifyResponseContract;
use Laravel\Fortify\Contracts\LockoutResponse as LockoutResponseContract;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Laravel\Fortify\Contracts\LogoutResponse as LogoutResponseContract;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;
use Laravel\Fortify\Contracts\PasswordResetResponse as PasswordResetResponseContract;
use Laravel\Fortify\Contracts\PasswordVerifiedResponse as PasswordVerifiedResponseContract;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse as SuccessfulPasswordResetLinkRequestResponseContract;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider as TwoFactorAuthenticationProviderContract;
use Laravel\Fortify\Http\Responses\FailedPasswordConfirmationResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordResetLinkRequestResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordResetResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordVerifyResponse;
use Laravel\Fortify\Http\Responses\LockoutResponse;
use Laravel\Fortify\Http\Responses\LoginResponse;
use Laravel\Fortify\Http\Responses\LogoutResponse;
use Laravel\Fortify\Http\Responses\PasswordConfirmedResponse;
use Laravel\Fortify\Http\Responses\PasswordResetResponse;
use Laravel\Fortify\Http\Responses\PasswordVerifiedResponse;
use Laravel\Fortify\Http\Responses\RegisterResponse;
use Laravel\Fortify\Http\Responses\SuccessfulPasswordResetLinkRequestResponse;

Expand Down Expand Up @@ -58,16 +58,16 @@ public function register()
*/
protected function registerResponseBindings()
{
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
$this->app->singleton(FailedPasswordConfirmationResponseContract::class, FailedPasswordConfirmationResponse::class);
$this->app->singleton(FailedPasswordResetLinkRequestResponseContract::class, FailedPasswordResetLinkRequestResponse::class);
$this->app->singleton(FailedPasswordResetResponseContract::class, FailedPasswordResetResponse::class);
$this->app->singleton(LockoutResponseContract::class, LockoutResponse::class);
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
$this->app->singleton(LogoutResponseContract::class, LogoutResponse::class);
$this->app->singleton(PasswordConfirmedResponseContract::class, PasswordConfirmedResponse::class);
$this->app->singleton(PasswordResetResponseContract::class, PasswordResetResponse::class);
$this->app->singleton(RegisterResponseContract::class, RegisterResponse::class);
$this->app->singleton(SuccessfulPasswordResetLinkRequestResponseContract::class, SuccessfulPasswordResetLinkRequestResponse::class);
$this->app->singleton(FailedPasswordResetLinkRequestResponseContract::class, FailedPasswordResetLinkRequestResponse::class);
$this->app->singleton(PasswordResetResponseContract::class, PasswordResetResponse::class);
$this->app->singleton(FailedPasswordResetResponseContract::class, FailedPasswordResetResponse::class);
$this->app->singleton(PasswordVerifiedResponseContract::class, PasswordVerifiedResponse::class);
$this->app->singleton(FailedPasswordVerifyResponseContract::class, FailedPasswordVerifyResponse::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\FailedPasswordVerifyResponse;
use Laravel\Fortify\Contracts\PasswordVerifiedResponse;
use Laravel\Fortify\Contracts\VerifyPasswordViewResponse;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse;

class VerifyPasswordController extends Controller
class ConfirmablePasswordController extends Controller
{
/**
* The guard implementation.
Expand All @@ -31,23 +30,23 @@ public function __construct(StatefulGuard $guard)
}

/**
* Show the verify password view.
* Show the confirm password view.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\VerifyPasswordViewResponse
*/
public function show(Request $request, VerifyPasswordViewResponse $response): VerifyPasswordViewResponse
public function show(Request $request)
{
return $response;
return app(ConfirmPasswordViewResponse::class);
}

/**
* Verify the user's password.
* Confirm the user's password.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Support\Responsable
*/
public function store(Request $request): Responsable
public function store(Request $request)
{
$username = config('fortify.username');

Expand All @@ -59,7 +58,7 @@ public function store(Request $request): Responsable
}

return $status
? app(PasswordVerifiedResponse::class)
: app(FailedPasswordVerifyResponse::class);
? app(PasswordConfirmedResponse::class)
: app(FailedPasswordConfirmationResponse::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\FailedPasswordVerifyResponse as FailedPasswordVerifyResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse as FailedPasswordConfirmationResponseContract;

class FailedPasswordVerifyResponse implements FailedPasswordVerifyResponseContract
class FailedPasswordConfirmationResponse implements FailedPasswordConfirmationResponseContract
{
/**
* Create an HTTP response that represents the object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\PasswordVerifiedResponse as PasswordVerifiedResponseContract;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;

class PasswordVerifiedResponse implements PasswordVerifiedResponseContract
class PasswordConfirmedResponse implements PasswordConfirmedResponseContract
{
/**
* Create an HTTP response that represents the object.
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Responses/SimpleViewResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Laravel\Fortify\Http\Responses;

use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\RegisterViewResponse;
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
use Laravel\Fortify\Contracts\ResetPasswordViewResponse;
use Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;
use Laravel\Fortify\Contracts\VerifyPasswordViewResponse;

class SimpleViewResponse implements
LoginViewResponse,
Expand All @@ -17,7 +17,7 @@ class SimpleViewResponse implements
RequestPasswordResetLinkViewResponse,
TwoFactorChallengeViewResponse,
VerifyEmailViewResponse,
VerifyPasswordViewResponse
ConfirmPasswordViewResponse
{
/**
* The name of the view or the callable used to generate the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,62 @@
namespace Laravel\Fortify\Tests;

use Illuminate\Foundation\Auth\User;
use Laravel\Fortify\Contracts\VerifyPasswordViewResponse;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;

class VerifyPasswordControllerTest extends OrchestraTestCase
class ConfirmablePasswordControllerTest extends OrchestraTestCase
{
protected $user;

public function test_the_verify_password_view_is_returned()
protected function setUp() : void
{
$this->mock(VerifyPasswordViewResponse::class)
parent::setUp();

$this->loadLaravelMigrations(['--database' => 'testbench']);

$this->artisan('migrate', ['--database' => 'testbench'])->run();

$this->user = TestConfirmPasswordUser::forceCreate([
'name' => 'Taylor Otwell',
'email' => 'taylor@laravel.com',
'password' => bcrypt('secret'),
]);
}

public function test_the_confirm_password_view_is_returned()
{
$this->mock(ConfirmPasswordViewResponse::class)
->shouldReceive('toResponse')
->andReturn(response('hello world'));

$response = $this->withoutExceptionHandling()->actingAs($this->user)->get(
'/user/password/verify'
'/user/confirm-password'
);

$response->assertStatus(200);
$response->assertSeeText('hello world');
}

public function test_password_can_be_verified()
public function test_password_can_be_confirmed()
{
$response = $this->withoutExceptionHandling()
->actingAs($this->user)
->withSession(['url.intended' => 'http://foo.com/bar'])
->post(
'/user/password/verify',
'/user/confirm-password',
['password' => 'secret']
);

$response->assertSessionHas('auth.password_confirmed_at');
$response->assertRedirect('http://foo.com/bar');
}

public function test_password_verification_can_fail()
public function test_password_confirmation_can_fail()
{
$response = $this->withoutExceptionHandling()
->actingAs($this->user)
->withSession(['url.intended' => 'http://foo.com/bar'])
->post(
'/user/password/verify',
'/user/confirm-password',
['password' => 'invalid']
);

Expand All @@ -53,45 +68,33 @@ public function test_password_verification_can_fail()
$this->assertNotEquals($response->getTargetUrl(), 'http://foo.com/bar');
}

public function test_password_can_be_verified_with_json()
public function test_password_can_be_confirmed_with_json()
{
$response = $this->actingAs($this->user)
->postJson(
'/user/password/verify',
'/user/confirm-password',
['password' => 'secret']
);

$response->assertStatus(201);
}

public function test_password_verification_can_fail_with_json()
public function test_password_confirmation_can_fail_with_json()
{
$response = $this->actingAs($this->user)
->postJson(
'/user/password/verify',
'/user/confirm-password',
['password' => 'invalid']
);

$response->assertJsonValidationErrors('password');
}

protected function setUp(): void
{
parent::setUp();
$this->loadLaravelMigrations(['--database' => 'testbench']);
$this->artisan('migrate', ['--database' => 'testbench'])->run();

$this->user = TestVerifyPasswordUser::forceCreate([
'name' => 'Taylor Otwell',
'email' => 'taylor@laravel.com',
'password' => bcrypt('secret'),
]);
}

protected function getEnvironmentSetUp($app)
{
$app['migrator']->path(__DIR__.'/../database/migrations');

$app['config']->set('auth.providers.users.model', TestVerifyPasswordUser::class);
$app['config']->set('auth.providers.users.model', TestConfirmPasswordUser::class);

$app['config']->set('database.default', 'testbench');

Expand All @@ -103,7 +106,7 @@ protected function getEnvironmentSetUp($app)
}
}

class TestVerifyPasswordUser extends User
class TestConfirmPasswordUser extends User
{
protected $table = 'users';
}

0 comments on commit 3ed5e87

Please sign in to comment.