ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilPasswordAssistanceGUI Class Reference
+ Inheritance diagram for ilPasswordAssistanceGUI:
+ Collaboration diagram for ilPasswordAssistanceGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 

Private Member Functions

 retrieveRequestedKey ()
 
 getClientId ()
 
 getBaseUrl ()
 
 buildUrl (string $script, array $query_parameters)
 
 emailTrafo ()
 
 mergeValuesTrafo ()
 
 saniziteArrayElementsTrafo ()
 
 trimIfStringTrafo ()
 
 getAssistanceForm ()
 
 showAssistanceForm (ILIAS\UI\Component\Input\Container\Form\Form $form=null)
 
 submitAssistanceForm ()
 If the submitted username and email address matches an entry in the user data table, then ILIAS creates a password assistance session for the user, and sends a password assistance mail to the email address. More...
 
 getAssignPasswordForm (string $pwassist_id=null)
 
 showAssignPasswordForm (ILIAS\UI\Component\Input\Container\Form\Form $form=null, string $pwassist_id='')
 Assign password form. More...
 
 submitAssignPasswordForm ()
 The key is used to retrieve the password assistance session. More...
 
 getUsernameAssistanceForm ()
 
 showUsernameAssistanceForm (ILIAS\UI\Component\Input\Container\Form\Form $form=null)
 
 submitUsernameAssistanceForm ()
 
 sendUsernameAssistanceMail (string $email, array $logins)
 
 showMessageForm (string $text, string $permanent_link_context)
 
 fillPermanentLink (string $context)
 

Private Attributes

const PERMANENT_LINK_TARGET_PW = 'pwassist'
 
const PERMANENT_LINK_TARGET_NAME = 'nameassist'
 
const PROP_USERNAME = 'username'
 
const PROP_EMAIL = 'email'
 
const PROP_PASSWORD = 'password'
 
const PROP_KEY = 'key'
 
ilCtrlInterface $ctrl
 
ilLanguage $lng
 
ilRbacReview $rbacreview
 
ilGlobalTemplateInterface $tpl
 
ilSetting $settings
 
ilErrorHandling $ilErr
 
RefineryFactory $refinery
 
HTTPServices $http
 
ilHelpGUI $help
 
ILIAS UI Factory $ui_factory
 
ILIAS UI Renderer $ui_renderer
 
ilObjUser $actor
 

Detailed Description

Definition at line 24 of file class.ilPasswordAssistanceGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilPasswordAssistanceGUI::__construct ( )

Definition at line 47 of file class.ilPasswordAssistanceGUI.php.

References $DIC, ILIAS\Repository\ctrl(), ILIAS\Repository\help(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

48  {
49  global $DIC;
50 
51  $this->ctrl = $DIC->ctrl();
52  $this->lng = $DIC->language();
53  $this->rbacreview = $DIC->rbac()->review();
54  $this->tpl = $DIC->ui()->mainTemplate();
55  $this->settings = $DIC->settings();
56  $this->ilErr = $DIC['ilErr'];
57  $this->help = $DIC->help();
58  $this->http = $DIC->http();
59  $this->refinery = $DIC->refinery();
60  $this->ui_factory = $DIC->ui()->factory();
61  $this->ui_renderer = $DIC->ui()->renderer();
62  $this->actor = $DIC->user();
63 
64  $this->help->setScreenIdComponent('init');
65  }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

Member Function Documentation

◆ buildUrl()

ilPasswordAssistanceGUI::buildUrl ( string  $script,
array  $query_parameters 
)
private
Parameters
array<string,string>$query_parameters

Definition at line 144 of file class.ilPasswordAssistanceGUI.php.

References $url, ilUtil\appendUrlParameterString(), and getBaseUrl().

Referenced by sendUsernameAssistanceMail(), and submitAssistanceForm().

144  : string
145  {
146  $url = implode('/', [
147  $this->getBaseUrl(),
148  ltrim($script, '/')
149  ]);
150 
152  $url,
153  http_build_query($query_parameters, '', '&')
154  );
155 
156  return $url;
157  }
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
$url
Definition: shib_logout.php:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emailTrafo()

ilPasswordAssistanceGUI::emailTrafo ( )
private

Definition at line 159 of file class.ilPasswordAssistanceGUI.php.

References ilUtil\is_email(), ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

Referenced by getAssistanceForm(), and getUsernameAssistanceForm().

159  : \ILIAS\Refinery\Transformation
160  {
161  return $this->refinery->custom()->constraint(
162  static function ($value): bool {
163  return is_string($value) && ilUtil::is_email($value);
164  },
165  $this->lng->txt('email_not_valid')
166  );
167  }
static is_email(string $a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilPasswordAssistanceGUI::executeCommand ( )

Definition at line 90 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), retrieveRequestedKey(), ILIAS\Repository\settings(), showAssignPasswordForm(), and showAssistanceForm().

90  : void
91  {
92  // check correct setup
93  if (!$this->settings->get('setup_ok')) {
94  $this->ilErr->raiseError('Setup is not completed. Please run setup routine again.', $this->ilErr->FATAL);
95  }
96 
97  // check hack attempts
98  if (!$this->settings->get('password_assistance')) {
99  $this->ilErr->raiseError($this->lng->txt('permission_denied'), $this->ilErr->MESSAGE);
100  }
101 
102  if ($this->actor->getId() > 0 && !$this->actor->isAnonymous()) {
103  $this->ilErr->raiseError($this->lng->txt('permission_denied'), $this->ilErr->MESSAGE);
104  }
105 
106  $this->lng->loadLanguageModule('pwassist');
107  $cmd = $this->ctrl->getCmd() ?? '';
108  $next_class = $this->ctrl->getNextClass($this);
109 
110  switch ($next_class) {
111  default:
112  if ($cmd !== '' && method_exists($this, $cmd)) {
113  $this->$cmd();
114  return;
115  }
116 
117  if ($this->retrieveRequestedKey() !== '') {
118  $this->showAssignPasswordForm(null, $this->retrieveRequestedKey());
119  } else {
120  $this->showAssistanceForm();
121  }
122  break;
123  }
124  }
showAssignPasswordForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null, string $pwassist_id='')
Assign password form.
showAssistanceForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null)
+ Here is the call graph for this function:

◆ fillPermanentLink()

ilPasswordAssistanceGUI::fillPermanentLink ( string  $context)
private

Definition at line 827 of file class.ilPasswordAssistanceGUI.php.

Referenced by showAssignPasswordForm(), showAssistanceForm(), showMessageForm(), and showUsernameAssistanceForm().

827  : void
828  {
829  $this->tpl->setPermanentLink('usr', null, $context);
830  }
$context
Definition: webdav.php:31
+ Here is the caller graph for this function:

◆ getAssignPasswordForm()

ilPasswordAssistanceGUI::getAssignPasswordForm ( string  $pwassist_id = null)
private

Definition at line 436 of file class.ilPasswordAssistanceGUI.php.

References $lng, ILIAS\Repository\ctrl(), ilSecuritySettingsChecker\getPasswordRequirementsInfo(), ilSecuritySettingsChecker\isPassword(), ILIAS\Repository\lng(), mergeValuesTrafo(), ILIAS\Repository\refinery(), saniziteArrayElementsTrafo(), trimIfStringTrafo(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by submitAssignPasswordForm().

437  {
438  $field_factory = $this->ui_factory->input()->field();
439 
440  $key = $field_factory
441  ->hidden()
442  ->withRequired(true)
443  ->withDedicatedName(self::PROP_KEY);
444  if ($pwassist_id !== null) {
445  $key = $key->withValue($pwassist_id);
446  }
447 
448  return $this->ui_factory
449  ->input()
450  ->container()
451  ->form()
452  ->standard(
453  $this->ctrl->getFormAction($this, 'submitAssignPasswordForm'),
454  [
455  $field_factory->section(
456  [
457  self::PROP_KEY => $key,
458  self::PROP_USERNAME => $field_factory
459  ->text($this->lng->txt('username'))
461  ->withRequired(true),
462  self::PROP_PASSWORD => $field_factory
463  ->password(
464  $this->lng->txt('password'),
466  )
467  ->withRequired(true)
468  ->withRevelation(true)
469  ->withAdditionalTransformation(
470  $this->refinery->custom()->constraint(
471  static function (ILIAS\Data\Password $value): bool {
473  trim($value->toString())
474  );
475  },
476  static function (Closure $lng, ILIAS\Data\Password $value): string {
477  $problem = $lng('passwd_invalid');
478  $custom_problem = null;
480  trim($value->toString()),
481  $custom_problem
482  )) {
483  $problem = $custom_problem;
484  }
485 
486  return $problem;
487  }
488  )
489  )
490  ->withAdditionalTransformation(
491  $this->refinery->custom()->transformation(
492  static function (ILIAS\Data\Password $value): string {
493  return trim($value->toString());
494  }
495  )
496  ),
497  ],
498  $this->lng->txt('password_assistance'),
499  ''
500  ),
501  ]
502  )
503  ->withSubmitLabel($this->lng->txt('submit'))
506  }
Interface Observer Contains several chained tasks and infos about them.
static isPassword(string $a_passwd, ?string &$customError=null)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAssistanceForm()

ilPasswordAssistanceGUI::getAssistanceForm ( )
private

Definition at line 194 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\ctrl(), emailTrafo(), ILIAS\Repository\lng(), mergeValuesTrafo(), saniziteArrayElementsTrafo(), trimIfStringTrafo(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by submitAssistanceForm().

195  {
196  $field_factory = $this->ui_factory->input()->field();
197 
198  return $this->ui_factory
199  ->input()
200  ->container()
201  ->form()
202  ->standard(
203  $this->ctrl->getFormAction($this, 'submitAssistanceForm'),
204  [
205  $field_factory->section(
206  [
207  self::PROP_USERNAME => $field_factory
208  ->text($this->lng->txt('username'))
210  ->withRequired(true),
211  self::PROP_EMAIL => $field_factory
212  ->text($this->lng->txt('email'))
213  ->withRequired(true)
214  ->withAdditionalTransformation($this->trimIfStringTrafo())
215  ->withAdditionalTransformation($this->emailTrafo()),
216  ],
217  $this->lng->txt('password_assistance'),
218  ''
219  ),
220  ]
221  )
222  ->withSubmitLabel($this->lng->txt('submit'))
225  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBaseUrl()

ilPasswordAssistanceGUI::getBaseUrl ( )
private

Definition at line 136 of file class.ilPasswordAssistanceGUI.php.

References ilUtil\_getHttpPath().

Referenced by buildUrl(), sendUsernameAssistanceMail(), and submitAssistanceForm().

136  : string
137  {
138  return rtrim(ilUtil::_getHttpPath(), '/');
139  }
static _getHttpPath()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClientId()

ilPasswordAssistanceGUI::getClientId ( )
private

Definition at line 85 of file class.ilPasswordAssistanceGUI.php.

References CLIENT_ID.

Referenced by sendUsernameAssistanceMail(), and submitAssistanceForm().

85  : string
86  {
87  return CLIENT_ID;
88  }
const CLIENT_ID
Definition: constants.php:41
+ Here is the caller graph for this function:

◆ getSafePostCommands()

ilPasswordAssistanceGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 131 of file class.ilPasswordAssistanceGUI.php.

131  : array
132  {
133  return ['submitAssignPasswordForm'];
134  }

◆ getUnsafeGetCommands()

ilPasswordAssistanceGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 126 of file class.ilPasswordAssistanceGUI.php.

126  : array
127  {
128  return [];
129  }

◆ getUsernameAssistanceForm()

ilPasswordAssistanceGUI::getUsernameAssistanceForm ( )
private

Definition at line 660 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\ctrl(), emailTrafo(), ILIAS\Repository\lng(), mergeValuesTrafo(), saniziteArrayElementsTrafo(), trimIfStringTrafo(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by submitUsernameAssistanceForm().

661  {
662  $field_factory = $this->ui_factory->input()->field();
663 
664  return $this->ui_factory
665  ->input()
666  ->container()
667  ->form()
668  ->standard(
669  $this->ctrl->getFormAction($this, 'submitUsernameAssistanceForm'),
670  [
671  $field_factory->section(
672  [
673  self::PROP_EMAIL => $field_factory
674  ->text($this->lng->txt('email'))
675  ->withRequired(true)
676  ->withAdditionalTransformation($this->trimIfStringTrafo())
677  ->withAdditionalTransformation($this->emailTrafo()),
678  ],
679  $this->lng->txt('username_assistance'),
680  ''
681  ),
682  ]
683  )
684  ->withSubmitLabel($this->lng->txt('submit'))
687  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mergeValuesTrafo()

ilPasswordAssistanceGUI::mergeValuesTrafo ( )
private

Definition at line 169 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\refinery().

Referenced by getAssignPasswordForm(), getAssistanceForm(), and getUsernameAssistanceForm().

169  : \ILIAS\Refinery\Transformation
170  {
171  return $this->refinery->custom()->transformation(static function (array $values): array {
172  return array_merge(...$values);
173  });
174  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveRequestedKey()

ilPasswordAssistanceGUI::retrieveRequestedKey ( )
private

Definition at line 67 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by executeCommand(), and showAssignPasswordForm().

67  : string
68  {
69  $key = $this->http->wrapper()->query()->retrieve(
70  'key',
71  $this->refinery->byTrying([
72  $this->refinery->kindlyTo()->string(),
73  $this->refinery->always(
74  $this->http->wrapper()->post()->retrieve(
75  'key',
76  $this->refinery->byTrying([$this->refinery->kindlyTo()->string(), $this->refinery->always('')])
77  )
78  )
79  ])
80  );
81 
82  return $key;
83  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saniziteArrayElementsTrafo()

ilPasswordAssistanceGUI::saniziteArrayElementsTrafo ( )
private

Definition at line 176 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\refinery(), and ilArrayUtil\stripSlashesRecursive().

Referenced by getAssignPasswordForm(), getAssistanceForm(), and getUsernameAssistanceForm().

176  : \ILIAS\Refinery\Transformation
177  {
178  return $this->refinery->custom()->transformation(static function (array $values): array {
179  return ilArrayUtil::stripSlashesRecursive($values);
180  });
181  }
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendUsernameAssistanceMail()

ilPasswordAssistanceGUI::sendUsernameAssistanceMail ( string  $email,
array  $logins 
)
private
Parameters
list<string>$logins

Definition at line 773 of file class.ilPasswordAssistanceGUI.php.

References $_SERVER, $DIC, buildUrl(), getBaseUrl(), getClientId(), ILIAS\Repository\lng(), and ILIAS\Repository\settings().

Referenced by submitUsernameAssistanceForm().

773  : void
774  {
775  global $DIC;
776 
777  $login_url = $this->buildUrl(
778  'pwassist.php',
779  [
780  'client_id' => $this->getClientId(),
781  'lang' => $this->lng->getLangKey()
782  ]
783  );
784 
785  $senderFactory = $DIC->mail()->mime()->senderFactory();
786  $sender = $senderFactory->system();
787 
788  $mm = new ilMimeMail();
789  $mm->Subject($this->lng->txt('pwassist_mail_subject'), true);
790  $mm->From($sender);
791  $mm->To($email);
792  $mm->Body(
793  str_replace(
794  ["\\n", "\\t"],
795  ["\n", "\t"],
796  sprintf(
797  $this->lng->txt('pwassist_username_mail_body'),
798  implode(",\n", $logins),
799  $this->getBaseUrl() . '/',
800  $_SERVER['REMOTE_ADDR'],
801  $email,
802  'mailto:' . $this->settings->get('admin_email'),
803  $login_url
804  )
805  )
806  );
807  $mm->Send();
808  }
buildUrl(string $script, array $query_parameters)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showAssignPasswordForm()

ilPasswordAssistanceGUI::showAssignPasswordForm ( ILIAS\UI\Component\Input\Container\Form\Form  $form = null,
string  $pwassist_id = '' 
)
private

Assign password form.

This form is used to assign a password to a username. To use this form, the following data must be provided as HTTP GET parameter, or in argument pwassist_id: key The key is used to retrieve the password assistance session. If the key is missing, or if the password assistance session has expired, the password assistance form will be shown instead of this form.

Definition at line 518 of file class.ilPasswordAssistanceGUI.php.

References db_pwassist_session_read(), fillPermanentLink(), ilUtil\getImagePath(), ILIAS\Repository\help(), ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), ilStartUpGUI\printToGlobalTemplate(), retrieveRequestedKey(), ilGlobalTemplateInterface\setVariable(), and showAssistanceForm().

Referenced by executeCommand(), and submitAssignPasswordForm().

521  : void {
522  $this->help->setSubScreenId('password_input');
523 
524  if ($pwassist_id === '') {
525  $pwassist_id = $this->retrieveRequestedKey();
526  }
527 
528  require_once __DIR__ . '/../../../../cli/inc.pwassist_session_handler.php';
529  $pwassist_session = db_pwassist_session_read($pwassist_id);
530  if (!is_array($pwassist_session) || $pwassist_session['expires'] < time()) {
531  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('pwassist_session_expired'));
532  $this->showAssistanceForm(null);
533  return;
534  }
535 
536  $tpl = ilStartUpGUI::initStartUpTemplate('tpl.pwassist_assignpassword.html', true);
537  $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('password_assistance'));
538  $tpl->setVariable(
539  'IMG_PAGEHEADLINE',
540  $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
541  ilUtil::getImagePath('standard/icon_auth.svg'),
542  $this->lng->txt('password_assistance')
543  ))
544  );
545 
546  $tpl->setVariable(
547  'TXT_ENTER_USERNAME_AND_NEW_PASSWORD',
548  $this->ui_renderer->render(
549  $this->ui_factory->messageBox()->info($this->lng->txt('pwassist_enter_username_and_new_password'))
550  )
551  );
552 
553  $tpl->setVariable('FORM', $this->ui_renderer->render($form ?? $this->getAssignPasswordForm($pwassist_id)));
554  $this->fillPermanentLink(self::PERMANENT_LINK_TARGET_PW);
556  }
static initStartUpTemplate( $a_tmpl, bool $a_show_back=false, bool $a_show_logout=false)
This method enriches the global template with some user interface elements (language selection...
showAssistanceForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static printToGlobalTemplate($tpl)
db_pwassist_session_read(string $pwassist_id)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showAssistanceForm()

ilPasswordAssistanceGUI::showAssistanceForm ( ILIAS\UI\Component\Input\Container\Form\Form  $form = null)
private

Definition at line 227 of file class.ilPasswordAssistanceGUI.php.

References fillPermanentLink(), ilUtil\getImagePath(), ILIAS\Repository\help(), ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), ilLegacyFormElementsUtil\prepareFormOutput(), ilStartUpGUI\printToGlobalTemplate(), ILIAS\Repository\settings(), and ilGlobalTemplateInterface\setVariable().

Referenced by executeCommand(), showAssignPasswordForm(), submitAssignPasswordForm(), and submitAssistanceForm().

227  : void
228  {
229  $this->help->setSubScreenId('password_assistance');
230 
231  $tpl = ilStartUpGUI::initStartUpTemplate('tpl.pwassist_assistance.html', true);
232  $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('password_assistance'));
233  $tpl->setVariable(
234  'IMG_PAGEHEADLINE',
235  $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
236  ilUtil::getImagePath('standard/icon_auth.svg'),
237  $this->lng->txt('password_assistance')
238  ))
239  );
240 
241  $tpl->setVariable(
242  'TXT_ENTER_USERNAME_AND_EMAIL',
243  $this->ui_renderer->render(
244  $this->ui_factory->messageBox()->info(
245  str_replace(
246  "\\n",
247  '<br />',
248  sprintf(
249  $this->lng->txt('pwassist_enter_username_and_email'),
250  '<a href="mailto:' . ilLegacyFormElementsUtil::prepareFormOutput(
251  $this->settings->get('admin_email')
252  ) . '">' . ilLegacyFormElementsUtil::prepareFormOutput($this->settings->get('admin_email')) . '</a>'
253  )
254  )
255  )
256  )
257  );
258 
259  $tpl->setVariable('FORM', $this->ui_renderer->render($form ?? $this->getAssistanceForm()));
260  $this->fillPermanentLink(self::PERMANENT_LINK_TARGET_PW);
262  }
static initStartUpTemplate( $a_tmpl, bool $a_show_back=false, bool $a_show_logout=false)
This method enriches the global template with some user interface elements (language selection...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static prepareFormOutput($a_str, bool $a_strip=false)
static printToGlobalTemplate($tpl)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showMessageForm()

ilPasswordAssistanceGUI::showMessageForm ( string  $text,
string  $permanent_link_context 
)
private

Definition at line 810 of file class.ilPasswordAssistanceGUI.php.

References fillPermanentLink(), ilUtil\getImagePath(), ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), ilStartUpGUI\printToGlobalTemplate(), and ilGlobalTemplateInterface\setVariable().

Referenced by submitAssignPasswordForm(), submitAssistanceForm(), and submitUsernameAssistanceForm().

810  : void
811  {
812  $tpl = ilStartUpGUI::initStartUpTemplate('tpl.pwassist_message.html', true);
813  $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('password_assistance'));
814  $tpl->setVariable(
815  'IMG_PAGEHEADLINE',
816  $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
817  ilUtil::getImagePath('standard/icon_auth.svg'),
818  $this->lng->txt('password_assistance')
819  ))
820  );
821 
822  $tpl->setVariable('TXT_TEXT', str_replace("\\n", '<br />', $text));
823  $this->fillPermanentLink($permanent_link_context);
825  }
static initStartUpTemplate( $a_tmpl, bool $a_show_back=false, bool $a_show_logout=false)
This method enriches the global template with some user interface elements (language selection...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static printToGlobalTemplate($tpl)
$text
Definition: xapiexit.php:21
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showUsernameAssistanceForm()

ilPasswordAssistanceGUI::showUsernameAssistanceForm ( ILIAS\UI\Component\Input\Container\Form\Form  $form = null)
private

Definition at line 689 of file class.ilPasswordAssistanceGUI.php.

References fillPermanentLink(), ilUtil\getImagePath(), ILIAS\Repository\help(), ilStartUpGUI\initStartUpTemplate(), ILIAS\Repository\lng(), ilLegacyFormElementsUtil\prepareFormOutput(), ilStartUpGUI\printToGlobalTemplate(), ILIAS\Repository\settings(), and ilGlobalTemplateInterface\setVariable().

Referenced by submitUsernameAssistanceForm().

689  : void
690  {
691  $this->help->setSubScreenId('username_assistance');
692 
693  $tpl = ilStartUpGUI::initStartUpTemplate('tpl.pwassist_username_assistance.html', true);
694  $tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('password_assistance'));
695  $tpl->setVariable(
696  'IMG_PAGEHEADLINE',
697  $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
698  ilUtil::getImagePath('standard/icon_auth.svg'),
699  $this->lng->txt('password_assistance')
700  ))
701  );
702 
703  $tpl->setVariable(
704  'TXT_ENTER_USERNAME_AND_EMAIL',
705  $this->ui_renderer->render(
706  $this->ui_factory->messageBox()->info(
707  str_replace(
708  "\\n",
709  '<br />',
710  sprintf(
711  $this->lng->txt('pwassist_enter_email'),
712  '<a href="mailto:' . ilLegacyFormElementsUtil::prepareFormOutput(
713  $this->settings->get('admin_email')
714  ) . '">' . ilLegacyFormElementsUtil::prepareFormOutput($this->settings->get('admin_email')) . '</a>'
715  )
716  )
717  )
718  )
719  );
720 
721  $tpl->setVariable('FORM', $this->ui_renderer->render($form ?? $this->getUsernameAssistanceForm()));
722  $this->fillPermanentLink(self::PERMANENT_LINK_TARGET_NAME);
724  }
static initStartUpTemplate( $a_tmpl, bool $a_show_back=false, bool $a_show_logout=false)
This method enriches the global template with some user interface elements (language selection...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static prepareFormOutput($a_str, bool $a_strip=false)
static printToGlobalTemplate($tpl)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ submitAssignPasswordForm()

ilPasswordAssistanceGUI::submitAssignPasswordForm ( )
private

The key is used to retrieve the password assistance session.

If the key is missing, or if the password assistance session has expired, the password assistance form will be shown instead of this form. If the password assistance session is valid, and if the username matches the username, for which the password assistance has been requested, and if the new password is valid, ILIAS assigns the password to the user. Note: To prevent replay attacks, the session is deleted when the password has been assigned successfully.

Definition at line 568 of file class.ilPasswordAssistanceGUI.php.

References db_pwassist_session_destroy(), db_pwassist_session_read(), getAssignPasswordForm(), ilObjectFactory\getInstanceByObjId(), ilObjUser\getLogin(), ILIAS\FileDelivery\http(), ilSecuritySettingsChecker\isPasswordValidForUserContext(), ILIAS\Repository\lng(), ilObjUser\resetPassword(), ilObjUser\setLastPasswordChangeToNow(), showAssignPasswordForm(), showAssistanceForm(), showMessageForm(), and ilObjUser\update().

568  : void
569  {
570  $form = $this->getAssignPasswordForm();
571  $form_valid = false;
572  $form_data = null;
573  if ($this->http->request()->getMethod() === 'POST') {
574  $form = $form->withRequest($this->http->request());
575  $form_data = $form->getData();
576  $form_valid = $form_data !== null;
577  }
578 
579  if (!$form_valid) {
580  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
581  $this->showAssistanceForm($form);
582  return;
583  }
584 
585  $username = $form_data[self::PROP_USERNAME];
586  $password = $form_data[self::PROP_PASSWORD];
587  $pwassist_id = $form_data[self::PROP_KEY];
588 
589  require_once __DIR__ . '/../../../../cli/inc.pwassist_session_handler.php';
590  $pwassist_session = db_pwassist_session_read($pwassist_id);
591  if (!is_array($pwassist_session) || $pwassist_session['expires'] < time()) {
592  $this->tpl->setOnScreenMessage(
593  'failure',
594  str_replace("\\n", '', $this->lng->txt('pwassist_session_expired'))
595  );
596  $this->showAssistanceForm($form);
597  } else {
598  $is_successful = true;
599  $message = '';
600 
601  $userObj = ilObjectFactory::getInstanceByObjId((int) $pwassist_session['user_id'], false);
602  if (!($userObj instanceof ilObjUser)) {
603  $message = $this->lng->txt('user_does_not_exist');
604  $is_successful = false;
605  }
606 
607  // check if the username entered by the user matches the
608  // one of the user object.
609  if ($is_successful && strcasecmp($userObj->getLogin(), $username) !== 0) {
610  $message = $this->lng->txt('pwassist_login_not_match');
611  $is_successful = false;
612  }
613 
614  $error_lng_var = '';
615  if ($is_successful &&
616  !ilSecuritySettingsChecker::isPasswordValidForUserContext($password, $userObj, $error_lng_var)) {
617  $message = $this->lng->txt($error_lng_var);
618  $is_successful = false;
619  }
620 
621  // End of validation
622  // If the validation was successful, we change the password of the
623  // user.
624  // ------------------
625  if ($is_successful) {
626  $is_successful = $userObj->resetPassword($password, $password);
627  if (!$is_successful) {
628  $message = $this->lng->txt('passwd_invalid');
629  }
630  }
631 
632  // If we are successful so far, we update the user object.
633  // ------------------
634  if ($is_successful) {
635  $userObj->setLastPasswordChangeToNow();
636  $userObj->update();
637  }
638 
639  // If we are successful, we destroy the password assistance
640  // session and redirect to the login page.
641  // Else we display the form again along with an error message.
642  // ------------------
643  if ($is_successful) {
644  db_pwassist_session_destroy($pwassist_id);
645  $this->showMessageForm(
646  $this->ui_renderer->render(
647  $this->ui_factory->messageBox()->info(
648  sprintf($this->lng->txt('pwassist_password_assigned'), $username)
649  )
650  ),
651  self::PERMANENT_LINK_TARGET_PW
652  );
653  } else {
654  $this->tpl->setOnScreenMessage('failure', str_replace("\\n", '', $message));
655  $this->showAssignPasswordForm($form, $pwassist_id);
656  }
657  }
658  }
db_pwassist_session_destroy(string $pwassist_id)
showAssignPasswordForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null, string $pwassist_id='')
Assign password form.
showAssistanceForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null)
static http()
Fetches the global http state from ILIAS.
db_pwassist_session_read(string $pwassist_id)
showMessageForm(string $text, string $permanent_link_context)
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
getAssignPasswordForm(string $pwassist_id=null)
+ Here is the call graph for this function:

◆ submitAssistanceForm()

ilPasswordAssistanceGUI::submitAssistanceForm ( )
private

If the submitted username and email address matches an entry in the user data table, then ILIAS creates a password assistance session for the user, and sends a password assistance mail to the email address.

For details about the creation of the session and the e-mail see function sendPasswordAssistanceMail().

Definition at line 271 of file class.ilPasswordAssistanceGUI.php.

References $_SERVER, $DIC, $duration, $GLOBALS, ANONYMOUS_ROLE_ID, ilAuthUtils\AUTH_LOCAL, ilAuthUtils\AUTH_SAML, buildUrl(), db_pwassist_create_id(), db_pwassist_session_write(), getAssistanceForm(), getBaseUrl(), getClientId(), ilObjUser\getEmail(), ilObject\getId(), ilLoggerFactory\getLogger(), ilObjUser\getLogin(), ilObjUser\getUserIdByLogin(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ilAuthUtils\isLocalPasswordEnabledForAuthMode(), ILIAS\Repository\lng(), ILIAS\Repository\settings(), showAssistanceForm(), showMessageForm(), and SYSTEM_ROLE_ID.

271  : void
272  {
273  $form = $this->getAssistanceForm();
274  $form_valid = false;
275  $form_data = null;
276  if ($this->http->request()->getMethod() === 'POST') {
277  $form = $form->withRequest($this->http->request());
278  $form_data = $form->getData();
279  $form_valid = $form_data !== null;
280  }
281 
282  if (!$form_valid) {
283  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
284  $this->showAssistanceForm($form);
285  return;
286  }
287 
288  $defaultAuth = ilAuthUtils::AUTH_LOCAL;
289  if ($GLOBALS['DIC']['ilSetting']->get('auth_mode')) {
290  $defaultAuth = $GLOBALS['DIC']['ilSetting']->get('auth_mode');
291  }
292 
293  $username = $form_data[self::PROP_USERNAME];
294  $email = $form_data[self::PROP_EMAIL];
295 
296  $assistance_callback = function () use ($defaultAuth, $username, $email): void {
297  $usr_id = ilObjUser::getUserIdByLogin($username);
298  if (!is_numeric($usr_id) || !($usr_id > 0)) {
299  ilLoggerFactory::getLogger('usr')->info(
300  sprintf(
301  'Could not process password assistance form (reason: no user found) %s / %s',
302  $username,
303  $email
304  )
305  );
306  return;
307  }
308 
309  $user = new ilObjUser($usr_id);
310  $email_addresses = array_map('strtolower', [$user->getEmail(), $user->getSecondEmail()]);
311 
312  if (!in_array(strtolower($email), $email_addresses, true)) {
313  if (implode('', $email_addresses) === '') {
314  ilLoggerFactory::getLogger('usr')->info(
315  sprintf(
316  'Could not process password assistance form (reason: account without email addresses): %s / %s',
317  $username,
318  $email
319  )
320  );
321  } else {
322  ilLoggerFactory::getLogger('usr')->info(
323  sprintf(
324  'Could not process password assistance form (reason: account email addresses differ from input): %s / %s',
325  $username,
326  $email
327  )
328  );
329  }
330  } elseif (
331  (
332  $user->getAuthMode(true) != ilAuthUtils::AUTH_LOCAL ||
333  ($user->getAuthMode(true) == $defaultAuth && $defaultAuth != ilAuthUtils::AUTH_LOCAL)
334  ) && !(
335  (int) $user->getAuthMode(true) === ilAuthUtils::AUTH_SAML &&
336  \ilAuthUtils::isLocalPasswordEnabledForAuthMode($user->getAuthMode(true))
337  )
338  ) {
339  ilLoggerFactory::getLogger('usr')->info(
340  sprintf(
341  'Could not process password assistance form (reason: not permitted for accounts using external authentication sources): %s / %s',
342  $username,
343  $email
344  )
345  );
346  } elseif ($this->rbacreview->isAssigned($user->getId(), ANONYMOUS_ROLE_ID) ||
347  $this->rbacreview->isAssigned($user->getId(), SYSTEM_ROLE_ID)) {
348  ilLoggerFactory::getLogger('usr')->info(
349  sprintf(
350  'Could not process password assistance form (reason: not permitted for system user or anonymous): %s / %s',
351  $username,
352  $email
353  )
354  );
355  } else {
356  $this->sendPasswordAssistanceMail($user);
357  }
358  };
359 
360  if (($assistance_duration = $this->settings->get('account_assistance_duration')) !== null) {
361  $duration = $this->http->durations()->callbackDuration((int) $assistance_duration);
362  $status = $duration->stretch($assistance_callback);
363  } else {
364  $status = $assistance_callback();
365  }
366 
367  $this->showMessageForm(sprintf($this->lng->txt('pwassist_mail_sent'), $email), self::PERMANENT_LINK_TARGET_PW);
368  }
static getLogger(string $a_component_id)
Get component logger.
const SYSTEM_ROLE_ID
Definition: constants.php:29
showAssistanceForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null)
$duration
static getUserIdByLogin(string $a_login)
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:30
showMessageForm(string $text, string $permanent_link_context)
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
static isLocalPasswordEnabledForAuthMode($a_authmode)
Check if local password validation is enabled for a specific auth_mode.
+ Here is the call graph for this function:

◆ submitUsernameAssistanceForm()

ilPasswordAssistanceGUI::submitUsernameAssistanceForm ( )
private

Definition at line 726 of file class.ilPasswordAssistanceGUI.php.

References $duration, ilLoggerFactory\getLogger(), ilObjUser\getUserLoginsByEmail(), getUsernameAssistanceForm(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), sendUsernameAssistanceMail(), ILIAS\Repository\settings(), showMessageForm(), and showUsernameAssistanceForm().

726  : void
727  {
728  $form = $this->getUsernameAssistanceForm();
729  $form_valid = false;
730  $form_data = null;
731  if ($this->http->request()->getMethod() === 'POST') {
732  $form = $form->withRequest($this->http->request());
733  $form_data = $form->getData();
734  $form_valid = $form_data !== null;
735  }
736 
737  if (!$form_valid) {
738  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
739  $this->showUsernameAssistanceForm($form);
740  return;
741  }
742 
743  $email = trim($form_data[self::PROP_EMAIL]);
744 
745  $assistance_callback = function () use ($email): void {
746  $logins = ilObjUser::getUserLoginsByEmail($email);
747 
748  if (is_array($logins) && count($logins) > 0) {
749  $this->sendUsernameAssistanceMail($email, $logins);
750  } else {
751  ilLoggerFactory::getLogger('usr')->info(
752  sprintf(
753  'Could not sent username assistance emails to (reason: no user found): %s',
754  $email
755  )
756  );
757  }
758  };
759 
760  if (($assistance_duration = $this->settings->get('account_assistance_duration')) !== null) {
761  $duration = $this->http->durations()->callbackDuration((int) $assistance_duration);
762  $status = $duration->stretch($assistance_callback);
763  } else {
764  $status = $assistance_callback();
765  }
766 
767  $this->showMessageForm($this->lng->txt('pwassist_mail_sent_generic'), self::PERMANENT_LINK_TARGET_NAME);
768  }
static getLogger(string $a_component_id)
Get component logger.
showUsernameAssistanceForm(ILIAS\UI\Component\Input\Container\Form\Form $form=null)
$duration
static http()
Fetches the global http state from ILIAS.
static getUserLoginsByEmail(string $a_email)
showMessageForm(string $text, string $permanent_link_context)
sendUsernameAssistanceMail(string $email, array $logins)
+ Here is the call graph for this function:

◆ trimIfStringTrafo()

ilPasswordAssistanceGUI::trimIfStringTrafo ( )
private

Definition at line 183 of file class.ilPasswordAssistanceGUI.php.

References ILIAS\Repository\refinery().

Referenced by getAssignPasswordForm(), getAssistanceForm(), and getUsernameAssistanceForm().

183  : \ILIAS\Refinery\Transformation
184  {
185  return $this->refinery->custom()->transformation(static function ($value) {
186  if (is_string($value)) {
187  $value = trim($value);
188  }
189 
190  return $value;
191  });
192  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $actor

ilObjUser ilPasswordAssistanceGUI::$actor
private

Definition at line 45 of file class.ilPasswordAssistanceGUI.php.

◆ $ctrl

ilCtrlInterface ilPasswordAssistanceGUI::$ctrl
private

Definition at line 34 of file class.ilPasswordAssistanceGUI.php.

◆ $help

ilHelpGUI ilPasswordAssistanceGUI::$help
private

Definition at line 42 of file class.ilPasswordAssistanceGUI.php.

◆ $http

HTTPServices ilPasswordAssistanceGUI::$http
private

Definition at line 41 of file class.ilPasswordAssistanceGUI.php.

◆ $ilErr

ilErrorHandling ilPasswordAssistanceGUI::$ilErr
private

Definition at line 39 of file class.ilPasswordAssistanceGUI.php.

◆ $lng

ilLanguage ilPasswordAssistanceGUI::$lng
private

Definition at line 35 of file class.ilPasswordAssistanceGUI.php.

Referenced by getAssignPasswordForm().

◆ $rbacreview

ilRbacReview ilPasswordAssistanceGUI::$rbacreview
private

Definition at line 36 of file class.ilPasswordAssistanceGUI.php.

◆ $refinery

RefineryFactory ilPasswordAssistanceGUI::$refinery
private

Definition at line 40 of file class.ilPasswordAssistanceGUI.php.

◆ $settings

ilSetting ilPasswordAssistanceGUI::$settings
private

Definition at line 38 of file class.ilPasswordAssistanceGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilPasswordAssistanceGUI::$tpl
private

Definition at line 37 of file class.ilPasswordAssistanceGUI.php.

◆ $ui_factory

ILIAS UI Factory ilPasswordAssistanceGUI::$ui_factory
private

Definition at line 43 of file class.ilPasswordAssistanceGUI.php.

◆ $ui_renderer

ILIAS UI Renderer ilPasswordAssistanceGUI::$ui_renderer
private

Definition at line 44 of file class.ilPasswordAssistanceGUI.php.

◆ PERMANENT_LINK_TARGET_NAME

const ilPasswordAssistanceGUI::PERMANENT_LINK_TARGET_NAME = 'nameassist'
private

Definition at line 27 of file class.ilPasswordAssistanceGUI.php.

◆ PERMANENT_LINK_TARGET_PW

const ilPasswordAssistanceGUI::PERMANENT_LINK_TARGET_PW = 'pwassist'
private

Definition at line 26 of file class.ilPasswordAssistanceGUI.php.

◆ PROP_EMAIL

const ilPasswordAssistanceGUI::PROP_EMAIL = 'email'
private

Definition at line 30 of file class.ilPasswordAssistanceGUI.php.

◆ PROP_KEY

const ilPasswordAssistanceGUI::PROP_KEY = 'key'
private

Definition at line 32 of file class.ilPasswordAssistanceGUI.php.

◆ PROP_PASSWORD

const ilPasswordAssistanceGUI::PROP_PASSWORD = 'password'
private

Definition at line 31 of file class.ilPasswordAssistanceGUI.php.

◆ PROP_USERNAME

const ilPasswordAssistanceGUI::PROP_USERNAME = 'username'
private

Definition at line 29 of file class.ilPasswordAssistanceGUI.php.


The documentation for this class was generated from the following file: