Commit 81a2b267 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(core) Fixes to user password handling and template features

Some functions were also added to ease public-forms coding

issue #3710
Showing with 75 additions and 12 deletions
+75 -12
......@@ -171,6 +171,8 @@ class template
}
}
/*! \brief Serialize this template for webservice
*/
function serialize()
{
$ret = array();
......@@ -188,6 +190,8 @@ class template
return $ret;
}
/*! \brief Deserialize values into the template
*/
function deserialize($values)
{
foreach ($values as $class => $class_values) {
......@@ -199,6 +203,34 @@ class template
return TRUE;
}
/*! \brief Get all attribute values
*
* this produces a format that you can send to setValues later (after a reset for instance)
*/
function getValues()
{
$ret = array();
foreach ($this->tabObject->by_object as $class => $plugin) {
$ret[$class] = array();
foreach ($plugin->attributesAccess as $name => $attr) {
$ret[$class][$name] = $attr->getValue();
}
}
return $ret;
}
/*! \brief Set values
*/
function setValues($values)
{
foreach ($values as $class => $class_values) {
foreach ($class_values as $name => $value) {
$this->tabObject->by_object[$class]->attributesAccess[$name]->setValue($value);
}
}
}
function save_object()
{
foreach ($this->tabObject->by_object as $plugin) {
......
......@@ -85,13 +85,27 @@ class FileAttribute extends Attribute
parent::serializeAttribute($attributes, $form);
if ($this->binary) {
$attributes[$this->getLdapName()]['value'] = base64_encode($attributes[$this->getLdapName()]['value']);
$attributes[$this->getLdapName()]['default'] = base64_encode($attributes[$this->getLdapName()]['default']);
$attributes[$this->getLdapName()]['binary'] = TRUE;
}
}
}
/*! \brief Serialize value for RPC requests
*
* \param mixed $value the value
*/
function serializeValue($value = NULL)
{
if ($value === NULL) {
$value = $this->getValue();
}
if ($this->binary) {
return base64_encode($value);
} else {
return $value;
}
}
/*! \brief Apply value from RPC requests
*
* \param mixed $value the value
......
......@@ -618,8 +618,8 @@ class Attribute
'required' => $this->isRequired(),
'disabled' => $this->disabled,
'description' => $this->getDescription(),
'value' => $this->getValue(),
'default' => $this->defaultValue,
'value' => $this->serializeValue(),
'default' => $this->serializeValue($this->defaultValue),
'type' => $type,
);
if (!$form) {
......@@ -643,6 +643,18 @@ class Attribute
$this->setValue($value);
}
/*! \brief Serialize value for RPC requests
*
* \param mixed $value the value
*/
function serializeValue($value = NULL)
{
if ($value === NULL) {
$value = $this->getValue();
}
return $value;
}
/*! \brief Add ACL information around display
*
* \param string $display the display information to pass through ACL
......
......@@ -124,6 +124,9 @@ class UserPasswordAttribute extends CompositeAttribute
function setValue ($value)
{
if (!is_array($value)) {
$value = $this->inputValue($value);
}
reset($value);
$key = key($value);
if ($this->attributes[0]->isDisabled() || ($value[$key] == '')) {
......@@ -143,7 +146,7 @@ class UserPasswordAttribute extends CompositeAttribute
{
$method = $this->attributes[0]->getValue();
if ($method != $this->previousMethod) {
if ($this->needPassword[$method]) {
if (isset($this->needPassword[$method]) && $this->needPassword[$method]) {
$hashEmpty = ($this->attributes[3]->getValue() == '');
$this->attributes[1]->setVisible(TRUE);
$this->attributes[1]->setRequired($hashEmpty);
......@@ -167,7 +170,10 @@ class UserPasswordAttribute extends CompositeAttribute
$pw_storage = $config->get_cfg_value('passwordDefaultHash', 'ssha');
$locked = FALSE;
$password = '';
if ($this->plugin->is_template) {
if ($this->plugin->is_template && !empty($value)) {
if ($value == '%askme%') {
return array('%askme%', '', '', $value, $locked);
}
list($value, $password) = explode('|', $value, 2);
}
if (preg_match ('/^{[^}]+}/', $value)) {
......@@ -189,12 +195,11 @@ class UserPasswordAttribute extends CompositeAttribute
function writeValues(array $values)
{
if ($this->needPassword[$values[0]] && ($values[1] == '')) {
if ($this->plugin->is_template) {
return '';
} else {
return $values[3];
}
if ($this->plugin->is_template && ($values[0] == '%askme%')) {
return '%askme%';
}
if (!$this->plugin->is_template && $this->needPassword[$values[0]] && ($values[1] == '')) {
return $values[3];
}
$temp = passwordMethod::get_available_methods();
if (!isset($temp[$values[0]])) {
......
  • bmortier @bmortier

    mentioned in issue #5988 (closed)

    By Côme Chilliet on 2019-05-02T08:03:35 (imported from GitLab)

    ·

    mentioned in issue #5988 (closed)

    By Côme Chilliet on 2019-05-02T08:03:35 (imported from GitLab)

    Toggle commit list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment