Skip to content
Snippets Groups Projects
Commit e3ef9f96 authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

fix editing passwordadmission, closes #1045

Closes #1045

Merge request studip/studip!613
parent 771a87ff
No related branches found
No related tags found
No related merge requests found
...@@ -116,12 +116,12 @@ class Admission_RuleController extends AuthenticatedController ...@@ -116,12 +116,12 @@ class Admission_RuleController extends AuthenticatedController
* configure a rule of the given type. * configure a rule of the given type.
* *
* @param String $ruleType Class name of the rule to check. * @param String $ruleType Class name of the rule to check.
* @param String $ruleId ID of the rule to save, or empty if this is a new rule.
*/ */
public function validate_action($ruleType) public function validate_action($ruleType, $ruleId = '')
{ {
$rules = AdmissionRule::getAvailableAdmissionRules(); $rules = AdmissionRule::getAvailableAdmissionRules();
$rule = new $ruleType(); $rule = new $ruleType($ruleId);
$this->errors = $rule->validate(Request::getInstance()); $this->errors = $rule->validate(Request::getInstance());
} }
} }
...@@ -4,7 +4,13 @@ use Studip\Button, Studip\LinkButton; ...@@ -4,7 +4,13 @@ use Studip\Button, Studip\LinkButton;
<div id="errormessage"></div> <div id="errormessage"></div>
<form action="<?= $controller->url_for('admission/rule/save', get_class($rule), $rule->getId()) ?>" <form action="<?= $controller->url_for('admission/rule/save', get_class($rule), $rule->getId()) ?>"
id="ruleform" class="default" id="ruleform" class="default"
onsubmit="return STUDIP.Admission.checkAndSaveRule('<?= $rule->getId() ?>', 'errormessage', '<?= $controller->url_for('admission/rule/validate', get_class($rule)) ?>', 'rules', '<?= $controller->url_for('admission/rule/save', get_class($rule), $rule->getId()) ?>')"> onsubmit="return STUDIP.Admission.checkAndSaveRule(
'<?= $rule->getId() ?>',
'errormessage',
'<?= $controller->url_for('admission/rule/validate', get_class($rule), $rule->getId()) ?>',
'rules',
'<?= $controller->url_for('admission/rule/save', get_class($rule), $rule->getId()) ?>'
)">
<?= $ruleTemplate ?> <?= $ruleTemplate ?>
<footer data-dialog-button> <footer data-dialog-button>
<input type="hidden" id="action" name="action" value=""> <input type="hidden" id="action" name="action" value="">
......
...@@ -19,20 +19,20 @@ require_once 'vendor/phpass/PasswordHash.php'; ...@@ -19,20 +19,20 @@ require_once 'vendor/phpass/PasswordHash.php';
class PasswordAdmission extends AdmissionRule class PasswordAdmission extends AdmissionRule
{ {
// --- ATTRIBUTES --- // --- ATTRIBUTES ---
/* /*
* Password hasher (phpass library) * Password hasher (phpass library)
*/ */
var $hasher = null; public $hasher = null;
/* /*
* Crypted password. * Crypted password.
*/ */
var $password = ''; public $password = '';
// --- OPERATIONS --- // --- OPERATIONS ---
public $new = false;
/** /**
* Standard constructor. * Standard constructor.
* *
...@@ -48,6 +48,7 @@ class PasswordAdmission extends AdmissionRule ...@@ -48,6 +48,7 @@ class PasswordAdmission extends AdmissionRule
$this->load(); $this->load();
} else { } else {
$this->id = $this->generateId('passwordadmissions'); $this->id = $this->generateId('passwordadmissions');
$this->new = true;
} }
} }
...@@ -173,7 +174,9 @@ class PasswordAdmission extends AdmissionRule ...@@ -173,7 +174,9 @@ class PasswordAdmission extends AdmissionRule
*/ */
public function setAllData($data) { public function setAllData($data) {
parent::setAllData($data); parent::setAllData($data);
$this->setPassword($data['password1']); if ($this->new || $data['password1'] !== '') {
$this->setPassword($data['password1']);
}
return $this; return $this;
} }
...@@ -227,10 +230,10 @@ class PasswordAdmission extends AdmissionRule ...@@ -227,10 +230,10 @@ class PasswordAdmission extends AdmissionRule
public function validate($data) public function validate($data)
{ {
$errors = parent::validate($data); $errors = parent::validate($data);
if (!$data['password1']) { if ($data['password1'] === '' && $this->new) {
$errors[] = _('Das Passwort darf nicht leer sein.'); $errors[] = _('Das Passwort darf nicht leer sein.');
} }
if ($data['password1'] != $data['password2']) { if ($data['password1'] !== $data['password2']) {
$errors[] = _('Das Passwort stimmt nicht mit der Wiederholung überein.'); $errors[] = _('Das Passwort stimmt nicht mit der Wiederholung überein.');
} }
return $errors; return $errors;
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
</label> </label>
<label> <label>
<?= _('Zugangspasswort') ?>: <?= _('Zugangspasswort') ?>:
<input type="password" name="password1" size="25" max="40" value="<?= htmlReady($rule->getPassword()) ?>" required> <input type="password" name="password1" size="25" max="40"
value="<?= htmlReady(Request::get('password1')) ?>" <?= $rule->new ? 'required' : ''?>>
</label> </label>
<br/>
<label> <label>
<?= _('Passwort wiederholen') ?>: <?= _('Passwort wiederholen') ?>:
<input type="password" name="password2" size="25" max="40" value="<?= htmlReady($rule->getPassword()) ?>" required> <input type="password" name="password2" size="25" max="40"
value="<?= htmlReady(Request::get('password2')) ?>" <?= $rule->new ? 'required' : ''?>>
</label> </label>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment