Skip to content

5. Forgot Password

dungda-0794 edited this page Feb 7, 2023 · 7 revisions

Forgot Password use service from package

Note: We need 2 API forgot password & change password

Get Token by email as the following:

# App\Http\Controllers\AuthController
public function postForgotPassword(Request $request)
{
    $email = $request->email;
    $status = $this->service->postForgotPassword($email, function ($token, $user) {
        // Use send mail from framework
        sendEmail($user, $token);
    });

    return response()->json([
        'ok' => $status,
        'type' => 'forgotPassword',
    ]);
}

Change new password

# App\Http\Controllers\AuthController
public function changePassword(Request $request)
{
    $params = $request->only(['old_password', 'password', 'token']);

    $status = $this->service->changePassword($params, function ($user, $attr) {
        // show user
    });

    return response()->json([
        'ok' => $status,
        'type' => 'changePassword',
    ]);
}

Clone this wiki locally