From 6a169bf5f4a2fc51f8ec0aa14ca6f7ab225f1f8d Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 4 Jul 2016 14:16:48 +0200 Subject: [PATCH] Fix https://github.com/getgrav/grav-plugin-admin/issues/682 saving a user when it's not yet created --- system/src/Grav/Common/User/User.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 374ce9a9a..3582d0387 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -124,14 +124,21 @@ class User extends Data public function save() { $file = $this->file(); + if ($file) { + $username = $this->get('username'); + + if (!$file->filename()) { + $locator = Grav::instance()['locator']; + $file->filename($locator->findResource('account://') . DS . strtolower($username) . YAML_EXT); + } + // if plain text password, hash it and remove plain text if ($this->password) { $this->hashed_password = Authentication::create($this->password); unset($this->password); } - $username = $this->get('username'); unset($this->username); $file->save($this->items); $this->set('username', $username);