0
votes

Kindly tell me how to implement the password reset functionality in my Laravel 5.1 application. I am using the JWT to give a user access to the system. Please, tell me how to implement 'forgot passsword' functionality. My web API is consumed by a mobile device and the user will follow the steps given below when a user understands that he has forgotten the password

1) In the login screen user will click 'Forgot password'

2) In the next step, the user will enter the email address and submits.

3) Server-side code compares the email with all the email registered within the system. If a match is found a link(self-destructing) to reset password is sent to the email address.

4) The user checks his email account to find the link and use it to reset a password.

Right now the code I have in user table is given down below.

<?php

namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


    public function events()
    {
        return $this->hasMany(Event::class);
    }


    public function request()
    {
        return $this->hasOne(Request::class);
    }
}
1
Yep, You should have to run a step by step process like you defined to achieve it. As you're using jwt you can identify the request and proceed and so on .. How many steps have you done so far?Sulthan Allaudeen

1 Answers

4
votes

www.laravel.com/docs/5.1/authentication#resetting-passwords

Refer there for detailed methods.

Assuming you havent made any modification to the laravel installation. it would be easy to make it.

User Model Editing

implement "Illuminate\Contracts\Auth\CanResetPassword" on App\User Model.

Database Table Migration

run "php artisan migrate" command on console.

Routes

add these routes to routes.php file.

// Password reset link request routes...
Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');

// Password reset routes...
Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');

View Files

Go to Resources/views/auth and make two new files called

password.blade.php and reset.blade.php

password.blade.php content => "http://pastebin.com/RkcFU130"

reset.blade.php content => "http://pastebin.com/6E5Kjqc4"

Email View

now make a new file called password.blade.php at resources/views/emails/password.blade.php.

paste this inside it.

Click here to reset your password: {{ url('password/reset/'.$token) }}

Post Reset Redirection

if you want to redirect user to a specific url. you can paste this code to Passwordcontroller.php. replace "dashboard" with the link you need to redirect to.

protected $redirectTo = '/dashboard';

thats all :)