diff --git a/src/admin/abstract/controller.php b/src/admin/abstract/controller.php index 557365e..388ecac 100644 --- a/src/admin/abstract/controller.php +++ b/src/admin/abstract/controller.php @@ -34,7 +34,7 @@ abstract class AbstractClubsController extends BaseController $this->filterPreCheck($values); // Check the input data - $error = ! $this->checkDataIsValid($values, true); + $error = ! $this->checkDataIsValid($values, true, Null); $view = $this->getNameOfView(); @@ -66,7 +66,7 @@ abstract class AbstractClubsController extends BaseController $this->filterPreCheck($values); // Check the input data - $error = ! $this->checkDataIsValid($values, false); + $error = ! $this->checkDataIsValid($values, false, $obj); $view = $this->getNameOfView(); @@ -101,7 +101,7 @@ abstract class AbstractClubsController extends BaseController protected function filterPreCheck(&$values){} - protected function checkDataIsValid($values, bool $isNew) + protected function checkDataIsValid($values, bool $isNew, $obj) { $error = false; // Check existence of the required fields @@ -147,7 +147,10 @@ abstract class AbstractClubsController extends BaseController $data = array(); foreach($this->getDataMapping() as $m => $i) - $data[$m] = $values[$m]; + { + if(isset($values[$m])) + $data[$m] = $values[$m]; + } return urlencode(json_encode($data)); } @@ -156,7 +159,12 @@ abstract class AbstractClubsController extends BaseController public function applyData($obj, $values) { - foreach($this->getDataMapping() as $m => $v) + $this->applyDataToObject($obj, $values, $this->getDataMapping()); + } + + protected function applyDataToObject($obj, $values, $mapping) + { + foreach($mapping as $m => $v) { $functionName = $this->getSetterMethodName($m, $v); @@ -165,14 +173,14 @@ abstract class AbstractClubsController extends BaseController continue; } - $value = (isset($values[$m])) ? $values[$m] : null; + $value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null; $obj->$functionName($value); } } private function getSetterMethodName($m, $options) { - if(isset($options['setter'])) + if(array_key_exists('setter', $options)) return $options['setter']; $firstChar = substr($m, 0, 1); diff --git a/src/admin/controllers/user.php b/src/admin/controllers/user.php index cc3dd6c..4cd1f0d 100644 --- a/src/admin/controllers/user.php +++ b/src/admin/controllers/user.php @@ -8,8 +8,13 @@ defined('_JEXEC') or die; class ClubsControllerUser extends AbstractClubsController { - private function checkUserName($username, $id = -1) + private function checkUserName($username, $obj = null) { + $id = -1; + + if(!is_null($obj)) + $id = $obj->getId(); + return ClubsUser::isUserNameFree($username, $id); } @@ -24,7 +29,7 @@ class ClubsControllerUser extends AbstractClubsController 'user'=>array('required'=>true, 'name'=>'Benutzername', 'filter'=>'cmd'), 'pwd'=>array('required'=>false, 'name'=>'Passwort', 'filter'=>'string', 'setter'=>'setPassword'), 'pwdConfirm'=>array('required'=>false, 'name'=>'Passwortwiederholung', 'filter'=>'string', 'setter'=>null), - 'name'=>array('required'=>true, 'name'=>'Benutzername', 'filter'=>'string'), + 'name'=>array('required'=>true, 'name'=>'Bürgerlicher Name', 'filter'=>'string'), 'address'=>array('required'=>true, 'name'=>'Adresse', 'filter'=>'string'), 'city'=>array('required'=>true, 'name'=>'Stadt', 'filter'=>'string'), 'mail'=>array('required'=>true, 'name'=>'E-Mail', 'filter'=>'string'), @@ -37,13 +42,13 @@ class ClubsControllerUser extends AbstractClubsController * {@inheritDoc} * @see AbstractClubsController::checkData() */ - protected function checkDataIsValid($values, $isNew) + protected function checkDataIsValid($values, $isNew, $obj) { - if(! parent::checkDataIsValid($values, $isNew)) + if(! parent::checkDataIsValid($values, $isNew, $obj)) return false; // TODO Auto-generated method stub - if(isset($values['pwd'])) + if(isset($values['pwd']) && strlen($values['pwd']) > 0) { $pwd = $values['pwd']; $pwdConfirm = $values['pwdConfirm']; @@ -70,7 +75,7 @@ class ClubsControllerUser extends AbstractClubsController } } - if(! $this->checkUserName(trim($values['user']))) + if(! $this->checkUserName(trim($values['user']), $obj)) { Factory::getApplication()->enqueueMessage('Username ' . $$values['user'] . ' ist nicht gültig.', 'error'); return false; @@ -97,7 +102,15 @@ class ClubsControllerUser extends AbstractClubsController public function applyData($obj, $values) { // TODO Auto-generated method stub - parent::applyData($obj, $values); + $mapping = $this->getDataMapping(); + + if(strlen($values['pwd']) == 0) + { + unset($values['pwd']); + unset($mapping['pwd']); + } + + $this->applyDataToObject($obj, $values, $mapping); } diff --git a/src/admin/mymodels/user.php b/src/admin/mymodels/user.php index 528aa75..892a772 100644 --- a/src/admin/mymodels/user.php +++ b/src/admin/mymodels/user.php @@ -233,16 +233,20 @@ class ClubsUser extends AbstractClubsModel if($this->id === 'new') return; - if(password_needs_rehash($this->password, PASSWORD_DEFAULT)) + if(password_needs_rehash($this->password, PASSWORD_DEFAULT) || true) { - $this->password = password_hash($password, PASSWORD_DEFAULT); + $copy = ClubsUser::loadUser($this->id); + $copy->password = password_hash($password, PASSWORD_DEFAULT); + $copy->save(); - $dbo = Factory::getDbo(); +// $this->password = password_hash($password, PASSWORD_DEFAULT); - $q = $dbo->getQuery(true); - $q->update(self::tableName)->set('password=' . $q->q($this->password))->where('id=' . (int) $this->id); - $dbo->setQuery($q); - $dbo->execute(); +// $dbo = Factory::getDbo(); + +// $q = $dbo->getQuery(true); +// $q->update(self::tableName)->set('password=' . $q->q($this->password))->where('id=' . (int) $this->id); +// $dbo->setQuery($q); +// $dbo->execute(); } } diff --git a/src/admin/views/positions/tmpl/default.php b/src/admin/views/positions/tmpl/default.php index cca0ee1..ff8a4fa 100644 --- a/src/admin/views/positions/tmpl/default.php +++ b/src/admin/views/positions/tmpl/default.php @@ -25,4 +25,4 @@ defined('_JEXEC') or die; -
'>Neues Angebot anlegen
+
'>Neuen Posten anlegen