简体   繁体   English

如何在 Lumen 6x 中实现默认 Laravel 重置密码

[英]How to Implement Default Laravel Reset Password in Lumen 6x

Im new to Laravel / Lumen framework and im trying to replicate the the default reset password trait for Laravel https://laravel.com/docs/5.7/passwords to my Lumen Project.我是 Laravel / Lumen 框架的新手,我试图将 Laravel https://laravel.com/docs/5.7/的默认重置密码特征复制到我的 Lumenwords 项目。 However, I stumbled upon this error when I post to sumbit email endpoints.但是,当我发布到 sumbit email 端点时,我偶然发现了这个错误。

Error Encountered {"message":"Target class [auth.password] does not exist."}遇到错误{"message":"Target class [auth.password] does not exist."}

My Route $router->post('password/email', 'AuthController@postEmail');我的路线$router->post('password/email', 'AuthController@postEmail');

Methods方法

    public function postEmail(Request $request)
    {
        return $this->sendResetLinkEmail($request);
    }
    /**
     * Send a reset link to the given user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function sendResetLinkEmail(Request $request)
    {
        // We will send the password reset link to this user. Once we have attempted
        // to send the link, we will examine the response then see the message we
        // need to show to the user. Finally, we'll send out a proper response.
        // dd($request->all());
        $response = $this->broker()->sendResetLink(
            $request->only('email')
        );

        return $response == Password::RESET_LINK_SENT
                        ? response()->json(true)
                        : response()->json(false);
    }

and it uses this class use Illuminate\Support\Facades\Password;它使用这个 class使用 Illuminate\Support\Facades\Password;

and I think the error is fired by this method我认为错误是由这种方法引发的

protected static function getFacadeAccessor()
    {
        return 'auth.password';
    }
}

I saw that this getFacadeAccesor return string is registered in namespace Illuminate\Foundation;我看到这个 getFacadeAccesor 返回字符串是在命名空间 Illuminate\Foundation 中注册的;

but I can't find this file in my Lumen vendor folder.但我在我的 Lumen 供应商文件夹中找不到这个文件。 Any workaround on this?有什么解决方法吗? Thank you!谢谢!

You could try registering the Illuminate\Auth\Passwords\PasswordResetServiceProvider Service Provider in bootstrap/app.php :您可以尝试在bootstrap/app.php中注册Illuminate\Auth\Passwords\PasswordResetServiceProvider服务提供程序:

...
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(Illuminate\Auth\Passwords\PasswordResetServiceProvider::class);

This Service Provider is what adds the binding for auth.password :该服务提供者为auth.password添加绑定:

protected function registerPasswordBroker()
{
    $this->app->singleton('auth.password', function ($app) {
        return new PasswordBrokerManager($app);
    });

    $this->app->bind('auth.password.broker', function ($app) {
        return $app->make('auth.password')->broker();
    });
}

That just resolves the auth.password binding, you still have other issues to deal with.这只是解决了auth.password绑定,您还有其他问题需要处理。

Your User will need to be using the Illuminate\Auth\Passwords\CanResetPassword trait but also the Illuminate\Notifications\Notifiable trait which you won't have as that Illuminate package isn't installed.您的用户将需要使用Illuminate\Auth\Passwords\CanResetPassword特征,但也需要使用Illuminate\Notifications\Notifiable特征,因为没有安装 Illuminate package。

You would have to not use the sendResetLink of the Password Broker, which uses the notify method (from Notifiable ) on the User, and build this part of the functionality yourself at the least.您不必使用密码代理的sendResetLink ,它使用用户的notify方法(来自Notifiable ),并且至少自己构建这部分功能。

Unfortunately if you start needing pieces of the Laravel Framework (Illuminate packages) that don't come with Lumen, you are going in the direction of using the Laravel Framework instead of Lumen, often times.不幸的是,如果您开始需要 Lumen 不附带的 Laravel 框架(Illuminate 包),那么您通常会使用 Laravel 框架而不是 Lumen。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM