commit 463604882c8cee5dcbddb610b42f4bac68480ec5
parent 3994a53e78f8e59ac10beb6be08f85856ab1d102
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 21 Jun 2011 14:35:34 +0200
Reworked usereditor to match the new deserialize model
Diffstat:
3 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/frontend/js/Models/User.js b/frontend/js/Models/User.js
@@ -2,7 +2,8 @@ Ext.define("PartKeepr.User", {
extend: "Ext.data.Model",
fields: [
{ id: 'id', name: 'id', type: 'int' },
- { name: 'username', type: 'string'}
+ { name: 'username', type: 'string'},
+ { name: 'password', type: 'string'}
],
proxy: PartKeepr.getRESTProxy("User"),
getRecordName: function () {
diff --git a/src/de/RaumZeitLabor/PartKeepr/User/User.php b/src/de/RaumZeitLabor/PartKeepr/User/User.php
@@ -1,11 +1,14 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\User;
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable;
+use de\RaumZeitLabor\PartKeepr\Util\Serializable;
+
declare(encoding = 'UTF-8');
use de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
/** @Entity @Table(name="PartKeeprUser") */
-class User extends BaseEntity {
+class User extends BaseEntity implements Serializable, Deserializable {
/** @Column(length=50,unique=true) */
private $username;
@@ -158,4 +161,23 @@ class User extends BaseEntity {
"username" => $this->getUsername()
);
}
+
+ /**
+ * Deserializes the user
+ * @param array $parameters The array with the parameters to set
+ */
+ public function deserialize (array $parameters) {
+ foreach ($parameters as $key => $value) {
+ switch ($key) {
+ case "username":
+ $this->setUsername($value);
+ break;
+ case "password":
+ if ($value !== "") {
+ $this->setHashedPassword($value);
+ }
+ break;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/User/UserService.php b/src/de/RaumZeitLabor/PartKeepr/User/UserService.php
@@ -50,8 +50,7 @@ class UserService extends AdminService implements RestfulService {
$this->requireParameter("username");
$user = new User;
-
- $this->setUserData($user);
+ $user->deserialize($this->getParameters());
UserManager::getInstance()->createUser($user);
@@ -59,20 +58,6 @@ class UserService extends AdminService implements RestfulService {
}
/**
- * Sets the data for this user. Used by update() and create().
- * @param User $user The user object
- */
- private function setUserData (User $user) {
- $user->setUsername($this->getParameter("username"));
-
- if ($this->hasParameter("password") && $this->getParameter("password") !== "") {
- $user->setHashedPassword($this->getParameter("password"));
- } else {
- $user->setHashedPassword("");
- }
- }
-
- /**
* Updates the user informations.
* @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update()
*/
@@ -81,7 +66,7 @@ class UserService extends AdminService implements RestfulService {
$this->requireParameter("username");
$user = UserManager::getInstance()->getUser($this->getParameter("id"));
- $this->setUserData($user);
+ $user->deserialize($this->getParameters());
PartKeepr::getEM()->flush();
return array("data" => $user->serialize());