تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Password Confirmation Overview0:00

Okay, let's take a look at confirming our password. For added security, sometimes you want to confirm a user's password before performing a task. You can see this in a few of Jetstream's features, like two-factor auth. There you see a model pop-up that asks for your password, and also for this feature here. So let's build this in our Fortify app. We're not going to have a model, but we'll have a Vue that does this. So as always, let's go ahead and define the Vue that we need in our FortifyServiceProvider. FortifyServiceProvider, let's add this in here. And again, let me change this to short closure syntax.

Register Confirm View0:37

FortifyServiceProvider, let's add this in here. And again, let me change this to short closure syntax. Okay, now we have to make a confirm password of Vue. So let's go ahead and do that. It's going to be an auth. Let me just duplicate one of these. I'll duplicate the password one. Actually, I'll just duplicate the forgot password one, since we're in auth here. Say, confirm password.blade.php. And this is the app layout.

Build Confirm Password Blade1:02

Say, confirm password.blade.php. And this is the app layout. So let's change this. Okay. And we can leave the errors. We don't really need this session status, because if it's successful, then it will just redirect to the intended page. And the route endpoint we're looking for is, let's bring up our routes first, route:list, compact. It's this one here.

list, compact. It's this one here. So user confirmPassword, and it's a POST request. Okay. confirmPassword. And all we need is a password field. So let's change these. And we don't want the value for the password. So let's remove that. This is password.

Protect Routes with Middleware1:55

So let's remove that. This is password. This is confirm. Okay. So now we just have to add the middleware on whatever feature we want to protect. So let's look for that middleware. It's built into Laravel. It's called password.confirm. So say, for example, I wanted to protect this feature here. Actually, let me put a link here to the main dashboard.

So say, for example, I wanted to protect this feature here. Actually, let me put a link here to the main dashboard. Let's go to our app, Blade PHP. The first link should be a dashboard link, dashboard, dashboard. Okay. So let's go to that. And when we click on profile, I want to confirm my password. So let's add that middleware in our routes file. So I want to protect the profile feature. So we'll put that middleware here.

So I want to protect the profile feature. So we'll put that middleware here. And now when I click on this profile, there we go. It's confirming or asking to confirm our password. I just have to change the H2. So back to that file. Okay. Confirm password. Let's try again, profile, confirm password. So Laravel knows where you're trying to go, but you have to confirm your password first.

Fix Endpoint and Test3:13

Let's try again, profile, confirmPassword. So Laravel knows where you're trying to go, but you have to confirm your password first. So let's put an incorrect password to check if the message works. And that does not work. Sorry. I have the incorrect endpoint. It should be /user/confirm-password. If you look here, okay, user confirmPassword. Try that one more time. Let's go to dashboard.

Try that one more time. Let's go to dashboard. Let's go to profile, incorrect password. There's the validation error message, correct password. And we should be redirected to that feature. And we are.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟