【问题标题】:Laravel edit password reminders behaviour (not delete the row on password change)Laravel 编辑密码提醒行为(不删除密码更改行)
【发布时间】:2014-02-09 22:46:38
【问题描述】:

我想更改密码提醒的行为方式。在 Laravel 中,一旦用户重置密码,在 password_reminders 表中创建的带有他们的令牌的行就会被删除。 我希望能够做其他事情(将其设置为已使用等)。 我想知道的是如何扩展这种行为。

PasswordBroker中的重置方法如下:(Illuminate/Auth/reminders/PasswordBroker.php)

public function reset(array $credentials, Closure $callback)
{
    // If the responses from the validate method is not a user instance, we will
    // assume that it is a redirect and simply return it from this method and
    // the user is properly redirected having an error message on the post.
    $user = $this->validateReset($credentials);

    if ( ! $user instanceof RemindableInterface)
    {
        return $user;
    }

    $pass = $credentials['password'];

    // Once we have called this callback, we will remove this token row from the
    // table and return the response from this callback so the user gets sent
    // to the destination given by the developers from the callback return.
    call_user_func($callback, $user, $pass);

    $this->reminders->delete($credentials['token']);

    return self::PASSWORD_RESET;
}

现在在我的 RemindersController 中,我正在调用外观密码:

$response = Password::reset($credentials, function($user, $password)
        {
            $user->password = Hash::make($password);

            $user->save();
        });

如何创建 PasswordBroker 的扩展并从我的控制器调用它?我是否也必须创建一个新的服务提供者? 所以编写一个扩展 PasswordBroker 的新类,编写一个扩展 ReminderServiceProvider 的新服务提供程序以及一个新的 Facade 并在我的控制器中调用该新 Facade 的新方法?这是正确的方法吗?

【问题讨论】:

    标签: php laravel laravel-4 ioc-container


    【解决方案1】:

    服务提供者和外观只是允许在应用程序级别访问类/对象的工具 - 这意味着在应用程序全局范围内。 就您而言,这取决于您希望在何处以及在何种情况下拥有 访问您的扩展课程。在很多情况下,命名空间是更好的选择。 例如,您在创建新控制器时已经在扩展 Laravel 内置类(您的控制器扩展了基本控制器),但您没有为该类创建新的提供者和外观。

    更新(如何创建新的服务提供者):

    首先使用您的提供商名称在 app/ 下创建新文件夹(我通常将我的提供商放在 app/services 下) 然后在 composer.json 中注册提供者命名空间

    接下来创建三个文件:

    1. 基类文件
    2. 提供者类文件
    3. 外观类文件

    如果您有帮助文件,请加上帮助文件。

    声明并定义所有内容,composer dump-autoload,您将拥有您的提供者。

    【讨论】:

    • 所以你认为创建一个扩展passwordbroker.php的类,有一个reset方法并通过命名空间直接调用扩展类/方法?不需要通过外墙?不过,如果能在应用程序范围内使用它会很好,那么我将如何去做呢?创建该类并为它创建一个服务提供者和一个外观?
    • 这样解释看起来很容易!我会为它喝彩。
    猜你喜欢
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2015-02-18
    相关资源
    最近更新 更多