51 $this->
ctrl = $DIC->ctrl();
52 $this->
lng = $DIC->language();
53 $this->rbacreview = $DIC->rbac()->review();
54 $this->tpl = $DIC->ui()->mainTemplate();
56 $this->ilErr = $DIC[
'ilErr'];
57 $this->
help = $DIC->help();
58 $this->
http = $DIC->http();
59 $this->actor = $DIC->user();
61 $this->ui_factory = $DIC->ui()->factory();
62 $this->ui_renderer = $DIC->ui()->renderer();
64 $this->
help->setScreenIdComponent(
'init');
69 $key = $this->
http->wrapper()->query()->retrieve(
72 $this->refinery->kindlyTo()->string(),
74 $this->
http->wrapper()->post()->retrieve(
76 $this->
refinery->byTrying([$this->refinery->kindlyTo()->string(), $this->
refinery->always(
'')])
95 if (!$this->
settings->get(
'setup_ok')) {
96 $this->ilErr->raiseError(
'Setup is not completed. Please run setup routine again.', $this->ilErr->FATAL);
99 if (!$this->
settings->get(
'password_assistance')) {
100 $this->ilErr->raiseError($this->
lng->txt(
'permission_denied'), $this->ilErr->MESSAGE);
103 if ($this->actor->getId() > 0 && !$this->actor->isAnonymous()) {
104 $this->ilErr->raiseError($this->
lng->txt(
'permission_denied'), $this->ilErr->MESSAGE);
107 $this->
lng->loadLanguageModule(
'pwassist');
108 $cmd = $this->
ctrl->getCmd() ??
'';
109 $next_class = $this->
ctrl->getNextClass($this);
111 switch ($next_class) {
113 if ($cmd !==
'' && method_exists($this, $cmd)) {
134 return [
'submitAssignPasswordForm'];
142 return rtrim(ILIAS_HTTP_PATH,
'/');
150 protected function buildUrl(
string $script, array $queryParameters): string
152 $url = implode(
'/', [
159 http_build_query($queryParameters, null,
'&')
169 $form->setFormAction($this->
ctrl->getFormAction($this,
'submitAssistanceForm'));
170 $form->setTarget(
'_parent');
173 $username->setRequired(
true);
174 $form->addItem($username);
177 $email->setRequired(
true);
180 $form->addCommandButton(
'submitAssistanceForm', $this->
lng->txt(
'submit'));
186 $this->
help->setSubScreenId(
'password_assistance');
188 $tpl = ilStartUpGUI::initStartUpTemplate(
'tpl.pwassist_assistance.html',
true);
191 $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
193 $this->
lng->txt(
'password_assistance')
196 $tpl->
setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'password_assistance'));
199 'TXT_ENTER_USERNAME_AND_EMAIL',
204 $this->
lng->txt(
'pwassist_enter_username_and_email'),
234 if (!$form->checkInput()) {
235 $form->setValuesByPost();
241 if (
$GLOBALS[
'DIC'][
'ilSetting']->
get(
'auth_mode')) {
242 $defaultAuth =
$GLOBALS[
'DIC'][
'ilSetting']->get(
'auth_mode');
245 $assistance_callback =
function () use ($form, $defaultAuth):
void {
246 $username = trim($form->getInput(
'username'));
247 $email = trim($form->getInput(
'email'));
250 if (!is_numeric($usrId) || !($usrId > 0)) {
253 'Could not process password assistance form (reason: no user found) %s / %s',
262 $user = new \ilObjUser($usrId);
263 $emailAddresses = array_map(
'strtolower', [$user->getEmail(), $user->getSecondEmail()]);
265 if (!in_array(strtolower($email), $emailAddresses)) {
266 if (0 === strlen(implode(
'', $emailAddresses))) {
268 'Could not process password assistance form (reason: account without email addresses): %s / %s',
274 'Could not process password assistance form (reason: account email addresses differ from input): %s / %s',
289 'Could not process password assistance form (reason: not permitted for accounts using external authentication sources): %s / %s',
298 'Could not process password assistance form (reason: not permitted for system user or anonymous): %s / %s',
303 $this->sendPasswordAssistanceMail($user);
307 if (null !== ($assistance_duration = $this->
settings->get(
"account_assistance_duration"))) {
308 $duration = $this->
http->durations()->callbackDuration((
int) $assistance_duration);
309 $status = $duration->stretch($assistance_callback);
311 $status = $assistance_callback();
315 sprintf($this->
lng->txt(
'pwassist_mail_sent'), $form->getInput(
'email')),
316 self::PERMANENT_LINK_TARGET_PW
330 public function sendPasswordAssistanceMail(
ilObjUser $userObj):
void 334 require_once
'include/inc.pwassist_session_handler.php';
339 if (session_status() !== PHP_SESSION_ACTIVE) {
345 $pwassist_session[
'pwassist_id'],
354 'lang' => $this->
lng->getLangKey(),
355 'key' => $pwassist_session[
'pwassist_id']
359 $alternative_pwassist_url = $this->
buildUrl(
363 'lang' => $this->
lng->getLangKey(),
364 'key' => $pwassist_session[
'pwassist_id']
369 $senderFactory = $DIC[
"mail.mime.sender.factory"];
370 $sender = $senderFactory->system();
373 $mm->Subject($this->
lng->txt(
'pwassist_mail_subject'),
true);
381 $this->
lng->txt(
'pwassist_mail_body'),
386 'mailto:' . $DIC->settings()->get(
"admin_email"),
387 $alternative_pwassist_url
397 $form->setFormAction($this->
ctrl->getFormAction($this,
'submitAssignPasswordForm'));
398 $form->setTarget(
'_parent');
401 $username->setRequired(
true);
402 $form->addItem($username);
406 $password->setRequired(
true);
407 $password->setUseStripSlashes(
false);
408 $form->addItem($password);
411 $key->setValue($pwassist_id);
412 $form->addItem(
$key);
413 $form->addCommandButton(
'submitAssignPasswordForm', $this->
lng->txt(
'submit'));
429 $this->
help->setSubScreenId(
'password_input');
433 if ($this->
http->wrapper()->query()->has(
'key')) {
434 $pwassist_id = $this->
http->wrapper()->query()->retrieve(
436 $this->
refinery->kindlyTo()->string()
442 require_once
'include/inc.pwassist_session_handler.php';
445 !is_array($pwassist_session) ||
446 count($pwassist_session) == 0 ||
447 $pwassist_session[
'expires'] < time()
449 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'pwassist_session_expired'));
452 $tpl = ilStartUpGUI::initStartUpTemplate(
'tpl.pwassist_assignpassword.html',
true);
455 $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
457 $this->
lng->txt(
'password_assistance')
460 $tpl->
setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'password_assistance'));
463 'TXT_ENTER_USERNAME_AND_NEW_PASSWORD',
464 $this->
lng->txt(
'pwassist_enter_username_and_new_password')
494 require_once
'include/inc.pwassist_session_handler.php';
500 if (!$form->checkInput()) {
501 $form->setValuesByPost();
506 $username = trim($form->getInput(
'username'));
507 $password = trim($form->getInput(
'password'));
508 $pwassist_id = $form->getInput(
'key');
514 !is_array($pwassist_session) ||
515 count($pwassist_session) == 0 ||
516 $pwassist_session[
'expires'] < time()
518 $this->tpl->setOnScreenMessage(
'failure', str_replace(
"\\n",
'', $this->
lng->txt(
'pwassist_session_expired')));
519 $form->setValuesByPost();
523 $is_successful =
true;
527 if (!$userObj || !($userObj instanceof \
ilObjUser)) {
529 $is_successful =
false;
534 if ($is_successful && strcasecmp($userObj->
getLogin(), $username) != 0) {
535 $message = $this->
lng->txt(
'pwassist_login_not_match');
536 $is_successful =
false;
542 $is_successful =
false;
549 if ($is_successful) {
550 $is_successful = $userObj->
resetPassword($password, $password);
551 if (!$is_successful) {
558 if ($is_successful) {
567 if ($is_successful) {
570 sprintf($this->
lng->txt(
'pwassist_password_assigned'), $username),
571 self::PERMANENT_LINK_TARGET_PW
574 $this->tpl->setOnScreenMessage(
'failure', str_replace(
"\\n",
'',
$message));
575 $form->setValuesByPost();
585 $form->setFormAction($this->
ctrl->getFormAction($this,
'submitUsernameAssistanceForm'));
586 $form->setTarget(
'_parent');
589 $email->setRequired(
true);
592 $form->addCommandButton(
'submitUsernameAssistanceForm', $this->
lng->txt(
'submit'));
607 $this->
help->setSubScreenId(
'username_assistance');
609 $tpl = ilStartUpGUI::initStartUpTemplate(
'tpl.pwassist_username_assistance.html',
true);
612 $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
614 $this->
lng->txt(
'password_assistance')
617 $tpl->
setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'password_assistance'));
620 'TXT_ENTER_USERNAME_AND_EMAIL',
625 $this->
lng->txt(
'pwassist_enter_email'),
655 if (!$form->checkInput()) {
656 $form->setValuesByPost();
662 $assistance_callback =
function () use ($form):
void {
663 $email = trim($form->getInput(
'email'));
666 if (is_array($logins) && count($logins) > 0) {
667 $this->sendUsernameAssistanceMail(
$email, $logins);
670 'Could not sent username assistance emails to (reason: no user found): %s',
676 if (null !== ($assistance_duration = $this->
settings->get(
"account_assistance_duration"))) {
677 $duration = $this->
http->durations()->callbackDuration((
int) $assistance_duration);
678 $status = $duration->stretch($assistance_callback);
680 $status = $assistance_callback();
683 $this->
showMessageForm($this->
lng->txt(
'pwassist_mail_sent_generic'), self::PERMANENT_LINK_TARGET_NAME);
696 public function sendUsernameAssistanceMail(
string $email, array $logins):
void 700 require_once
'include/inc.pwassist_session_handler.php';
706 'lang' => $this->
lng->getLangKey()
711 $senderFactory = $DIC[
"mail.mime.sender.factory"];
712 $sender = $senderFactory->system();
715 $mm->Subject($this->
lng->txt(
'pwassist_mail_subject'),
true);
723 $this->
lng->txt(
'pwassist_username_mail_body'),
724 join(
",\n", $logins),
728 'mailto:' . $this->
settings->get(
"admin_email"),
741 $tpl = ilStartUpGUI::initStartUpTemplate(
'tpl.pwassist_message.html',
true);
742 $tpl->
setVariable(
'TXT_PAGEHEADLINE', $this->
lng->txt(
'password_assistance'));
745 $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
747 $this->
lng->txt(
'password_assistance')
751 $tpl->
setVariable(
'TXT_TEXT', str_replace(
"\\n",
'<br />', $text));
758 $this->tpl->setPermanentLink(
'usr', null, $context);
resetPassword(string $raw, string $raw_retype)
Resets the user password.
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
db_pwassist_session_destroy($pwassist_id)
destroy session
static getLogger(string $a_component_id)
Get component logger.
db_pwassist_session_read($pwassist_id)
showAssignPasswordForm(ilPropertyFormGUI $form=null, string $pwassist_id='')
Assign password form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
RefineryFactory $refinery
getAssignPasswordForm(string $pwassist_id)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
buildUrl(string $script, array $queryParameters)
static printToGlobalTemplate($tpl)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const PERMANENT_LINK_TARGET_PW
static getUserIdByLogin(string $a_login)
ILIAS UI Factory $ui_factory
static http()
Fetches the global http state from ILIAS.
getClientId()
as replacement for "this->ilias"
static getUserLoginsByEmail(string $a_email)
submitUsernameAssistanceForm()
Reads the submitted data from the password assistance form.
showMessageForm(string $text, string $permanent_link_context)
This form is used to show a message to the user.
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getUsernameAssistanceForm()
showAssistanceForm(ilPropertyFormGUI $form=null)
fillPermanentLink(string $context)
const PERMANENT_LINK_TARGET_NAME
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilGlobalTemplateInterface $tpl
static isLocalPasswordEnabledForAuthMode($a_authmode)
Check if local password validation is enabled for a specific auth_mode.
submitAssignPasswordForm()
Reads the submitted data from the password assistance form.
Error Handling & global info handling uses PEAR error class.
submitAssistanceForm()
Reads the submitted data from the password assistance form.
getSafePostCommands()
This method must return a list of safe POST commands.
setLastPasswordChangeToNow()
ILIAS UI Renderer $ui_renderer
db_pwassist_session_write($pwassist_id, $maxlifetime, $user_id)
Writes serialized session data to the database.
Interface ilCtrlSecurityInterface provides ilCtrl security information.
getBaseUrl()
Returns the ILIAS http path without a trailing /.
showUsernameAssistanceForm(ilPropertyFormGUI $form=null)
Shows the password assistance form.