partkeepr

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

commit 432c01b8a1651588cc51de05c59f98dc591d8682
parent 8d3b837efa850e1fa6aff25fc2f94acdc255db9c
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu,  5 Nov 2015 16:24:41 +0100

Added initial user preference loading

Diffstat:
Msrc/PartKeepr/AuthBundle/Action/LoginAction.php | 24++++++++++++++++++++++--
Msrc/PartKeepr/AuthBundle/Entity/User.php | 90++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/PartKeepr/AuthBundle/Resources/config/actions.xml | 1+
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/store/UserPreferenceStore.js | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js | 14+++++++-------
5 files changed, 93 insertions(+), 38 deletions(-)

diff --git a/src/PartKeepr/AuthBundle/Action/LoginAction.php b/src/PartKeepr/AuthBundle/Action/LoginAction.php @@ -5,7 +5,7 @@ namespace PartKeepr\AuthBundle\Action; use Dunglas\ApiBundle\Action\ActionUtilTrait; -use Dunglas\ApiBundle\Api\ResourceInterface; +use PartKeepr\AuthBundle\Services\UserPreferenceService; use PartKeepr\AuthBundle\Services\UserService; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Serializer\Serializer; @@ -24,17 +24,37 @@ class LoginAction */ private $serializer; + /** + * @var UserPreferenceService + */ + private $userPreferenceService; + public function __construct( UserService $userService, - Serializer $serializer + Serializer $serializer, + UserPreferenceService $userPreferenceService ) { $this->userService = $userService; $this->serializer = $serializer; + $this->userPreferenceService = $userPreferenceService; } public function __invoke (Request $request) { $user = $this->userService->getUser(); + $userPreferences = $this->userPreferenceService->getPreferences($user); + + $arrayUserPreferences = array(); + + foreach ($userPreferences as $userPreference) { + $arrayUserPreferences[] = array( + "preferenceKey" => $userPreference->getPreferenceKey(), + "preferenceValue" => $userPreference->getPreferenceValue() + ); + } + + $user->setInitialUserPreferences(json_encode($arrayUserPreferences)); + return $user; } } diff --git a/src/PartKeepr/AuthBundle/Entity/User.php b/src/PartKeepr/AuthBundle/Entity/User.php @@ -55,6 +55,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; @@ -76,9 +77,17 @@ class User extends BaseEntity implements UserInterface, EquatableInterface private $tipHistories; /** + * Holds the initial serialized user preferences + * @VirtualField(type="string") + * @Groups({"default"}) + * @var string + */ + private $initialUserPreferences; + + /** * Creates a new user object. * - * @param string $username The username to set (optional) + * @param string $username The username to set (optional) * @param UserProvider $provider The authentification provider * * @throws \Exception @@ -107,6 +116,22 @@ class User extends BaseEntity implements UserInterface, EquatableInterface } /** + * @return string + */ + public function getInitialUserPreferences() + { + return $this->initialUserPreferences; + } + + /** + * @param string $initialUserPreferences + */ + public function setInitialUserPreferences($initialUserPreferences) + { + $this->initialUserPreferences = $initialUserPreferences; + } + + /** * @return mixed */ public function getTipHistories() @@ -172,26 +197,6 @@ class User extends BaseEntity implements UserInterface, EquatableInterface } /** - * Returns the username. - * - * @return string The username - */ - public function getUsername() - { - return $this->username; - } - - /** - * Sets the username. - * - * @param string $username The username to set. - */ - public function setUsername($username) - { - $this->username = $username; - } - - /** * Returns the admin flag * * @return boolean True if the user is an admin @@ -219,14 +224,16 @@ class User extends BaseEntity implements UserInterface, EquatableInterface $this->password = $password; } - public function getNewPassword () { + public function getNewPassword() + { return $this->newPassword; } /** * Sets the new password. Used for password changes */ - public function setNewPassword ($password) { + public function setNewPassword($password) + { $this->newPassword = $password; } @@ -271,17 +278,21 @@ class User extends BaseEntity implements UserInterface, EquatableInterface /** * Returns if the user is a legacy user + * * @return bool */ - public function isLegacy () { + public function isLegacy() + { return $this->legacy; } /** * Marks a user as a legacy user + * * @param bool|true $legacy */ - public function setLegacy ($legacy = true) { + public function setLegacy($legacy = true) + { $this->legacy = $legacy; } @@ -295,15 +306,18 @@ class User extends BaseEntity implements UserInterface, EquatableInterface return $this->lastSeen; } - public function getRoles () { + public function getRoles() + { return array(); } - public function getSalt () { + public function getSalt() + { return ""; } - public function eraseCredentials () { + public function eraseCredentials() + { } @@ -319,4 +333,24 @@ class User extends BaseEntity implements UserInterface, EquatableInterface return true; } + + /** + * Returns the username. + * + * @return string The username + */ + public function getUsername() + { + return $this->username; + } + + /** + * Sets the username. + * + * @param string $username The username to set. + */ + public function setUsername($username) + { + $this->username = $username; + } } diff --git a/src/PartKeepr/AuthBundle/Resources/config/actions.xml b/src/PartKeepr/AuthBundle/Resources/config/actions.xml @@ -34,6 +34,7 @@ <service id="partkeepr.auth.login" class="PartKeepr\AuthBundle\Action\LoginAction"> <argument type="service" id="partkeepr.userservice"/> <argument type="service" id="api.serializer"/> + <argument type="service" id="partkeepr.user_preference_service"/> </service> <service id="partkeepr.auth.change_password" class="PartKeepr\AuthBundle\Action\ChangePasswordAction"> <argument type="service" id="partkeepr.userservice"/> diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/store/UserPreferenceStore.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/store/UserPreferenceStore.js @@ -9,7 +9,7 @@ Ext.define('PartKeepr.data.store.UserPreferenceStore', { /** * Automatically load the store */ - autoLoad: true, + autoLoad: false, /** * The model to use diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js b/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js @@ -89,14 +89,11 @@ Ext.application({ { this.createGlobalStores(); - if (window.parameters.userPreferences) { - PartKeepr.getApplication().setInitialUserPreferences(window.parameters.userPreferences); - } + var initialUserPreferences = Ext.decode(this.getLoginManager().getUser().get("initialUserPreferences")); - if (PartKeepr.initialUserPreferences) { - var records = this.getUserPreferenceStore().getProxy().getReader().read(PartKeepr.initialUserPreferences); - this.getUserPreferenceStore().loadRecords(records.records); - } + var records = this.getUserPreferenceStore().getProxy().getReader().read(initialUserPreferences); + + this.getUserPreferenceStore().loadRecords(records.records); this.createPartManager(); @@ -300,6 +297,7 @@ Ext.application({ this.userPreferenceStore = Ext.create("PartKeepr.data.store.UserPreferenceStore", { model: 'PartKeepr.AuthBundle.Entity.UserPreference', + autoLoad: false }); this.tipOfTheDayStore = Ext.create("PartKeepr.data.store.TipOfTheDayStore"); @@ -336,6 +334,8 @@ Ext.application({ if (decodedValue === null) { return value; + } else { + return decodedValue; } } else { return (typeof defaultValue == "undefined") ? null : defaultValue;