Laravel API Resetting and Forgot Password

Refer to the ForgotPasswordController and ResetPasswordController files in the Auth folder.

For convenience, we directly copy these two files first:

Comment 2020-04-13 232940

Paste into the Api folder:

Comment 2020-04-13 233100

Modify the namespace of the two class files to:

namespace App\Http\Controllers\Api;

When we forget the password, the main thing we need is the sendResetLinkEmail method in the SendsPasswordResetEmails trait.

Comment 2020-04-13 233330Comment 2020-04-13 233345

So we add a route in api.php to direct the reset request to this method;

Route::post('/password/email', 'Api\ForgotPasswordController@sendResetLinkEmail');

For the same password reset request, the reset method in the trait ResetsPasswords is needed.

Comment 2020-04-13 233925

So we add a route in api.php to direct the reset request to this method;

Route::post('/password/reset', 'Api\ResetPasswordController@reset');

Note: If you need to rewrite the methods in the two traits, for example, our api request needs a json to return {Laravel 7.x version already supports judgment to return json result}, you can use Ctrl + o in ForgotPasswordController and ResetPasswordController respectively Shortcut keys can be rewritten.

Guess you like

Origin www.cnblogs.com/dzkjz/p/12695096.html