API Rest with Laravel 5.6 Passport Authentication — Reset Password (Part 4)

https://medium.com/modulr/api-rest-with-laravel-5-6-passport-authentication-reset-password-part-4-50d27455dcca

API Rest with Laravel 5.6 Passport Authentication — Reset Password (Part 4)

Alfredo BarronAlfredo BarronFollowAug 2, 2018 · 6 min read

We will learn to create a password reset systemImage for postImage for posthttps://www.vecteezy.com

Step 1. Update migration

php artisan make:model PasswordReset -m

In first step, we require to update the migration file database/migrations/xxx_create_password_resets_table.php like bellow code:

public function up()
{
    Schema::create('password_resets', function (Blueprint $table) {
        $table->increments('id');
        $table->string('email')->index();
        $table->string('token');
        $table->timestamps();
    });
}

Step 2. Create PasswordReset model

Open your terminal or command prompt and run bellow command:

This command will create app/PasswordReset.php file, in this file set fillable inputs.

Step 3. Create Notifications

We create two notifications PaswordResetRequest and PasswordResetSuccess, in your terminal or command prompt run bellow commands:

This command will create app/Notifications/PasswordResetRequest.php and app/Notifications/PasswordResetSuccess.php files.

In the PasswordResetRequest.php file add the next code:

In the PasswordResetSuccess.php file add the next code:

Step 4. Create API Routes

We will create api routes. Laravel provide routes/api.php file for write web services route. So, let’s add new route on that file.

Step 5: Install Dependencies

We use Carbon package to help with dates, in your terminal run bellow command:

Step 6: Create Controller

In this step we have to create new controller and three api method. So let’s create PasswordResetController and put bellow code:

Now we are ready to run our example so run bellow command to quick run:

Tests

Now, we can simple test by rest client tools (Postman), So I test it and you can see below screenshots.

In this api you have to set two header as listed below:

Request Password ResetImage for postImage for post

When request password reset will created token in data baseImage for postImage for post

When request password reset will receive a email with the link to Reset Password.Image for postImage for post

Find Password Reset

If the token is active response with token dataImage for postImage for post

If the token is not active the response is a 404 errorImage for postImage for post

Reset Password

If the token is active response with User dataImage for postImage for post

If the token is not active the response is a 404 errorImage for postImage for post

Thanks for reading! I’m Alfredo Barrón, Feel free to connect with me via Twitter.

Part 1. Passport Authentication Part 2. Confirm account + notifications Part 3. Generate avatar Part 4. Reset Password Part 5. Send Notifications with Queues on Redis

Resources

GitHub Postman collections

Last updated

Was this helpful?