partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 42074d61c531cb853b3d96834c6df5f001ad7ed5
parent 083c3862334dbdbdf0ca05c802f221a065917cae
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 12 Oct 2015 14:24:22 +0200

Auto-migrate legacy users to new users if a password is set

Diffstat:
Mapp/config/partkeepr.yml | 2+-
Mapp/config/security.yml | 6+-----
Msrc/PartKeepr/AuthBundle/Action/PostUserAction.php | 2+-
Msrc/PartKeepr/AuthBundle/Action/PutUserAction.php | 2+-
Msrc/PartKeepr/AuthBundle/Entity/User.php | 24+++++++++++++++++++++---
Msrc/PartKeepr/AuthBundle/Services/UserService.php | 8++++----
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/User/UserEditor.js | 19+++++++++++++++++--
Msrc/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php | 1+
Msrc/PartKeepr/SetupBundle/Controller/SetupController.php | 6++++++
Msrc/PartKeepr/SetupBundle/Resources/views/parameters.php.twig | 2++
Mweb/setup/js/PartKeeprSetup.js | 1+
11 files changed, 56 insertions(+), 17 deletions(-)

diff --git a/app/config/partkeepr.yml b/app/config/partkeepr.yml @@ -1,7 +1,7 @@ partkeepr: image_cache_directory: %kernel.cache_dir%/imagecache/ cronjob_check: false - authentication_provider: PartKeepr.Auth.HTTPBasicAuthenticationProvider + authentication_provider: %authentication_provider% directories: iclogo: %kernel.root_dir%/../data/images/iclogo/ temp: %kernel.root_dir%/../data/temp/ diff --git a/app/config/security.yml b/app/config/security.yml @@ -22,11 +22,7 @@ security: legacy: id: partkeepr_legacy_user_provider in_memory: - memory: - users: - admin: - password: x61Ey612Kl2gpFL56FT9weDnpSo4AV8j8+qx2AuTHdRyY036xxzTTrw10Wq3+4qQyB+XURPWx1ONxp3Y3pB37A== - roles: 'ROLE_ADMIN' + memory: ~ fos_userbundle: id: fos_user.user_provider.username fr3d_ldapbundle: diff --git a/src/PartKeepr/AuthBundle/Action/PostUserAction.php b/src/PartKeepr/AuthBundle/Action/PostUserAction.php @@ -70,7 +70,7 @@ class PostUserAction ); $data->setProvider($this->userService->getBuiltinProvider()); - + $data->setLegacy(false); $this->userService->syncData($data); $data->setPassword(""); diff --git a/src/PartKeepr/AuthBundle/Action/PutUserAction.php b/src/PartKeepr/AuthBundle/Action/PutUserAction.php @@ -75,8 +75,8 @@ class PutUserAction ); $this->userService->syncData($data); - $data->setPassword(""); + $data->setLegacy(false); return $data; } diff --git a/src/PartKeepr/AuthBundle/Entity/User.php b/src/PartKeepr/AuthBundle/Entity/User.php @@ -25,12 +25,19 @@ class User extends BaseEntity implements UserInterface, EquatableInterface private $username; /** + * @Groups({"default"}) * @ORM\Column(length=32,nullable=true) */ private $password; /** + * @var string + */ + private $plainPassword; + + /** * @Assert\Email() + * @Groups({"default"}) * @ORM\Column(length=255,nullable=true) * @var string */ @@ -44,6 +51,7 @@ class User extends BaseEntity implements UserInterface, EquatableInterface /** * Marks a user as a legacy user (=old md5 auth) * @ORM\Column(type="boolean") + * @Groups({"default"}) * @var boolean */ private $legacy; @@ -195,18 +203,28 @@ class User extends BaseEntity implements UserInterface, EquatableInterface */ public function getPassword() { - return $this->password; + return $this->plainPassword; } /** * Sets the user's password. * - * @Groups({"default"}) * @param string $password */ public function setPassword($password) { - $this->password = $password; + $this->plainPassword = $password; + } + + public function getPlainPassword () { + return $this->plainPassword; + } + + /** + * Sets the plain password. Used for password changes + */ + public function setPlainPassword ($password) { + } /** diff --git a/src/PartKeepr/AuthBundle/Services/UserService.php b/src/PartKeepr/AuthBundle/Services/UserService.php @@ -98,14 +98,14 @@ class UserService if ($FOSUser === null) { - if ($user->getPassword() == "") { + if ($user->getPlainPassword() == "") { throw new \Exception("Password must be set"); } - $FOSUser = $this->userManipulator->create($user->getUsername(), $user->getPassword(), "", true, false); + $FOSUser = $this->userManipulator->create($user->getUsername(), $user->getPlainPassword(), "", true, false); } - if ($user->getPassword() != "") { - $this->userManipulator->changePassword($user->getUsername(), $user->getPassword()); + if ($user->getPlainPassword() != "") { + $this->userManipulator->changePassword($user->getUsername(), $user->getPlainPassword()); } diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/UserEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/UserEditor.js @@ -3,7 +3,6 @@ Ext.define('PartKeepr.UserEditor', { alias: 'widget.UserEditor', saveText: i18n("Save User"), - model: 'PartKeepr.User', titleProperty: 'username', initComponent: function () @@ -23,8 +22,24 @@ Ext.define('PartKeepr.UserEditor', { inputType: "password", name: 'password', fieldLabel: i18n("Password") + }, { + xtype: 'displayfield', + itemId: 'legacyField', + fieldLabel: i18n("Legacy User"), + value: i18n('This user is a legacy user. You must provide a password in order to change the user. Please read <a href="https://wiki.partkeepr.org/wiki/Authentication" target="_blank">the PartKeepr Wiki regarding Authentication</a> for further information.'), + hidden: true } ]; + this.on("startEdit", this.onEditStart, this, {delay: 200}); + this.callParent(); - }}); + }, + onEditStart: function () + { + console.log(this.record); + if (this.record.get("legacy") === true) { + this.down("#legacyField").setVisible(true); + } + } +}); diff --git a/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php b/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php @@ -67,6 +67,7 @@ class ExistingConfigParserController extends SetupController $config["database"]["port"] = $legacyConfig["partkeepr.database.port"]; } + $config["legacyAuth"] = true; $response["config"] = $config; } diff --git a/src/PartKeepr/SetupBundle/Controller/SetupController.php b/src/PartKeepr/SetupBundle/Controller/SetupController.php @@ -176,6 +176,8 @@ class SetupController extends Controller "user_email" => null, ); + $parameters["legacyAuth"] = false; + $secret = ""; for ($i = 0; $i < 32; $i++) { $secret .= chr(65 + rand(0, 16)); @@ -195,6 +197,10 @@ class SetupController extends Controller $parameters["ldap"] = $this->applyIf($parameters["ldap"], $data["ldap"]); } + if (array_key_exists("legacyAuth", $data)) { + $parameters["legacyAuth"] = $data["legacyAuth"]; + } + array_walk_recursive($parameters, function (&$item, $key) { $item = var_export($item, true); }); diff --git a/src/PartKeepr/SetupBundle/Resources/views/parameters.php.twig b/src/PartKeepr/SetupBundle/Resources/views/parameters.php.twig @@ -15,6 +15,8 @@ $container->setParameter('mailer_user', {{ mailer.username|raw }}); $container->setParameter('mailer_password', {{ mailer.password|raw }}); $container->setParameter('mailer_auth_mode', {{ mailer.auth_mode|raw }}); +$container->setParameter('authentication_provider', '{% if legacyAuth %}PartKeepr.Auth.HTTPBasicAuthenticationProvider{% else %}PartKeepr.Auth.WSSEAuthenticationProvider{% endif %}'); + $container->setParameter('locale', 'en'); $container->setParameter('secret', {{ secret|raw }}); diff --git a/web/setup/js/PartKeeprSetup.js b/web/setup/js/PartKeeprSetup.js @@ -26,6 +26,7 @@ Ext.application({ email: "" }, existingConfig: false, + legacyAuth: false, authKey: "" };