getgrav / grav-plugin-admin

Grav Admin Plugin
http://getgrav.org
MIT License
355 stars 223 forks source link

Password field in plugin is changed to null on plugin config save #2319

Closed jgonyea closed 1 year ago

jgonyea commented 1 year ago

Possibly related to https://github.com/getgrav/grav-plugin-admin/issues/249

To Replicate:

Observed Behavior:

Password field in the plugin is now overridden to null.

Expected Behavior:

Password is left unchanged.

rhukster commented 1 year ago

I think your running into a somewhat known situation.. the password field doesn't show the current password, but there's no other logic to skip if null. Email plugin has a solution to this problem though:

    public function onAdminSave(Event $event)
    {
        /** @var Data $obj */
        $obj = $event['object'];

        if ($obj instanceof Data && $obj->blueprints()->getFilename() === 'email/blueprints') {
            $current_pw = $this->grav['config']->get('plugins.email.mailer.smtp.password');
            $new_pw = $obj->get('mailer.smtp.password');
            if (!empty($current_pw) && empty($new_pw)) {
                $obj->set('mailer.smtp.password', $current_pw);
            }

        }
    }

Basically checks if this is an email plugin save, and if so loads the current stored pw, compares it to the form value. It only updates the password with the new one if the new one is not empty.