ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPasswordInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected bool $skip_syntax_check = false;
30  protected string $value = "";
31  protected int $size = 20;
32  protected string $validateauthpost = "";
33  protected bool $requiredonauth = false;
34  protected int $maxlength = 0;
35  protected bool $use_strip_slashes = true;
39  protected bool $autocomplete_disabled = true;
40  protected string $retypevalue = "";
41  protected bool $retype = false;
42 
43  public function __construct(
44  string $a_title = "",
45  string $a_postvar = ""
46  ) {
47  global $DIC;
48 
49  $this->lng = $DIC->language();
50  parent::__construct($a_title, $a_postvar);
51  $this->setRetype(true);
52  $this->setSkipSyntaxCheck(false);
53  }
54 
55  public function setValue(
56  string $a_value
57  ): void {
58  $this->value = $a_value;
59  }
60 
61  public function getValue(): string
62  {
63  return $this->value;
64  }
65 
66  public function setRetype(bool $a_val): void
67  {
68  $this->retype = $a_val;
69  }
70 
71  public function getRetype(): bool
72  {
73  return $this->retype;
74  }
75 
76  public function setRetypeValue(string $a_retypevalue): void
77  {
78  $this->retypevalue = $a_retypevalue;
79  }
80 
81  public function getRetypeValue(): string
82  {
83  return $this->retypevalue;
84  }
85 
86  public function setMaxLength(int $a_maxlength): void
87  {
88  $this->maxlength = $a_maxlength;
89  }
90 
91  public function getMaxLength(): int
92  {
93  return $this->maxlength;
94  }
95 
96  public function setSize(int $a_size): void
97  {
98  $this->size = $a_size;
99  }
100 
101  public function setValueByArray(array $a_values): void
102  {
103  $this->setValue($a_values[$this->getPostVar()] ?? "");
104  $this->setRetypeValue($a_values[$this->getPostVar() . "_retype"] ?? "");
105  }
106 
107  public function getSize(): int
108  {
109  return $this->size;
110  }
111 
112  // Set Validate required status against authentication POST var.
113  public function setValidateAuthPost(string $a_validateauthpost): void
114  {
115  $this->validateauthpost = $a_validateauthpost;
116  }
117 
118  public function getValidateAuthPost(): string
119  {
121  }
122 
123  // Set input required, if authentication mode allows password setting.
124  public function setRequiredOnAuth(bool $a_requiredonauth): void
125  {
126  $this->requiredonauth = $a_requiredonauth;
127  }
128 
129  public function getRequiredOnAuth(): bool
130  {
131  return $this->requiredonauth;
132  }
133 
134  public function setSkipSyntaxCheck(bool $a_val): void
135  {
136  $this->skip_syntax_check = $a_val;
137  }
138 
139  public function getSkipSyntaxCheck(): bool
140  {
142  }
143 
144  public function setDisableHtmlAutoComplete(bool $a_value): void
145  {
146  $this->autocomplete_disabled = $a_value;
147  }
148 
149  public function isHtmlAutoCompleteDisabled(): bool
150  {
152  }
153 
159  public function setUseStripSlashes(bool $a_stat): void
160  {
161  $this->use_strip_slashes = $a_stat;
162  }
163 
164  public function getUseStripSlashes(): bool
165  {
167  }
168 
169  public function checkInput(): bool
170  {
171  $lng = $this->lng;
172 
173  $pass_value = $this->getInput();
174  $retype_value = ($this->getUseStripSlashes())
175  ? $this->str($this->getPostVar() . "_retype")
176  : $this->raw($this->getPostVar() . "_retype");
177 
178  if ($this->getRequired() && trim($pass_value) == "") {
179  $this->setAlert($lng->txt("msg_input_is_required"));
180  return false;
181  }
182  if ($this->getValidateAuthPost() != "") {
183  $auth = ilAuthUtils::_getAuthMode($this->str($this->getValidateAuthPost()));
184 
185  // check, if password is required dependent on auth mode
187  && trim($pass_value) == "") {
188  $this->setAlert($lng->txt("form_password_required_for_auth"));
189  return false;
190  }
191 
192  // check, if password is allowed to be set for given auth mode
193  if (trim($pass_value) != "" &&
195  $this->setAlert($lng->txt("form_password_not_allowed_for_auth"));
196  return false;
197  }
198  }
199  if ($this->getRetype() &&
200  ($pass_value != $retype_value)) {
201  $this->setAlert($lng->txt("passwd_not_match"));
202  return false;
203  }
204  if (!$this->getSkipSyntaxCheck() &&
205  !ilSecuritySettingsChecker::isPassword($pass_value, $custom_error) &&
206  $pass_value != "") {
207  if ($custom_error != '') {
208  $this->setAlert($custom_error);
209  } else {
210  $this->setAlert($lng->txt("passwd_invalid"));
211  }
212  return false;
213  }
214 
215  return $this->checkSubItemsInput();
216  }
217 
218  public function getInput(): string
219  {
220  if ($this->getUseStripSlashes()) {
221  return $this->str($this->getPostVar());
222  }
223  return $this->raw($this->getPostVar());
224  }
225 
226  public function render(): string
227  {
228  $lng = $this->lng;
229 
230  $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "components/ILIAS/Form");
231 
232  if ($this->getRetype()) {
233  $ptpl->setCurrentBlock("retype");
234  $ptpl->setVariable("RSIZE", $this->getSize());
235  $ptpl->setVariable("RID", $this->getFieldId());
236  if ($this->getMaxLength() > 0) {
237  $ptpl->setCurrentBlock("rmaxlength");
238  $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength());
239  $ptpl->parseCurrentBlock();
240  }
241  $ptpl->setVariable("RPOST_VAR", $this->getPostVar());
242 
243  if ($this->isHtmlAutoCompleteDisabled()) {
244  $ptpl->setVariable("RAUTOCOMPLETE", "autocomplete=\"off\"");
245  }
246 
247  // this is creating an "auto entry" in the setup, if the retype is missing
248  /*$retype_value = ($this->getRetypeValue() != "")
249  ? $this->getRetypeValue()
250  : $this->getValue();*/
251  $retype_value = $this->getRetypeValue();
252  $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($retype_value));
253  if ($this->getDisabled()) {
254  $ptpl->setVariable(
255  "RDISABLED",
256  " disabled=\"disabled\""
257  );
258  }
259  $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password"));
260  $ptpl->parseCurrentBlock();
261  }
262 
263  if (strlen($this->getValue())) {
264  $ptpl->setCurrentBlock("prop_password_propval");
265  $ptpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getValue()));
266  $ptpl->parseCurrentBlock();
267  }
268  $ptpl->setVariable("POST_VAR", $this->getPostVar());
269  $ptpl->setVariable("ID", $this->getFieldId());
270  $ptpl->setVariable("SIZE", $this->getSize());
271  if ($this->getMaxLength() > 0) {
272  $ptpl->setCurrentBlock("maxlength");
273  $ptpl->setVariable("MAXLENGTH", $this->getMaxLength());
274  $ptpl->parseCurrentBlock();
275  }
276  if ($this->getDisabled()) {
277  $ptpl->setVariable(
278  "DISABLED",
279  " disabled=\"disabled\""
280  );
281  }
282  if ($this->isHtmlAutoCompleteDisabled()) {
283  $ptpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
284  }
285  if ($this->getRequired()) {
286  $ptpl->setVariable("REQUIRED", "required=\"required\"");
287  }
288  return $ptpl->get();
289  }
290 
291  public function insert(ilTemplate $a_tpl): void
292  {
293  $html = $this->render();
294 
295  $a_tpl->setCurrentBlock("prop_generic");
296  $a_tpl->setVariable("PROP_GENERIC", $html);
297  $a_tpl->parseCurrentBlock();
298  }
299 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setRetypeValue(string $a_retypevalue)
static _getAuthMode(?string $a_auth_mode)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setRequiredOnAuth(bool $a_requiredonauth)
static isPassword(string $a_passwd, ?string &$customError=null)
static prepareFormOutput($a_str, bool $a_strip=false)
static _allowPasswordModificationByAuthMode($a_auth_mode)
Allow password modification.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
__construct(string $a_title="", string $a_postvar="")
global $DIC
Definition: shib_login.php:26
This class represents a password property in a property form.
setValidateAuthPost(string $a_validateauthpost)
setUseStripSlashes(bool $a_stat)
En/disable use of stripslashes.
setMaxLength(int $a_maxlength)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setValueByArray(array $a_values)
__construct(Container $dic, ilPlugin $plugin)
This class represents a property that may include a sub form.
setDisableHtmlAutoComplete(bool $a_value)