ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestPasswordProtectionGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\GlobalScreen\Services as GlobalScreen;
23
33{
34 public const CMD_SHOW_PASSWORD_FORM = 'showPasswordForm';
35 public const CMD_SAVE_ENTERED_PASSWORD = 'saveEnteredPassword';
36 public const CMD_BACK_TO_INFO_SCREEN = 'backToInfoScreen';
37
38 private string $next_command_class;
39 private string $next_command_cmd;
40
41 public function __construct(
42 private ilCtrlInterface $ctrl,
43 private ilGlobalTemplateInterface $tpl,
44 private ilLanguage $lng,
45 private ilTestPlayerAbstractGUI $parent_gui,
46 private ilTestPasswordChecker $password_checker,
47 private RequestDataCollector $testrequest,
48 private GlobalScreen $global_screen
49 ) {
50 }
51
52 public function executeCommand(): void
53 {
54 $this->ctrl->saveParameter($this, 'nextCommand');
55 $next_cmd = explode('::', $this->testrequest->getNextCommand());
56 $this->setNextCommandClass($next_cmd[0]);
57 $this->setNextCommandCmd($next_cmd[1]);
58
59 $this->ctrl->saveParameter($this->parent_gui, 'lock');
60
61 switch ($this->ctrl->getNextClass()) {
62 default:
63
64 $cmd = $this->ctrl->getCmd() . 'Cmd';
65 $this->$cmd();
66 }
67 }
68
69 protected function buildPasswordMsg(): string
70 {
71 if (!$this->password_checker->wrongUserEnteredPasswordExist()) {
72 return '';
73 }
74
76 $this->lng->txt('tst_password_entered_wrong_password'),
77 'failure'
78 );
79 }
80
82 {
83 $form = new ilPropertyFormGUI();
84 $form->setTitle($this->lng->txt("tst_password_form"));
85 $form->setDescription($this->lng->txt("tst_password_introduction"));
86
87 $form->setFormAction($this->ctrl->getFormAction($this));
88 $form->addCommandButton(self::CMD_SAVE_ENTERED_PASSWORD, $this->lng->txt("submit"));
89 $form->addCommandButton(self::CMD_BACK_TO_INFO_SCREEN, $this->lng->txt("cancel"));
90
91 $inp = new ilPasswordInputGUI($this->lng->txt("tst_password"), 'password');
92 $inp->setRequired(true);
93 $inp->setRetype(false);
94 $form->addItem($inp);
95 return $form;
96 }
97
98 private function showPasswordFormCmd(): void
99 {
100 $this->global_screen->tool()->context()->current()->getAdditionalData()->replace(
102 $this->parent_gui->getObject()->getTitle() . ' - ' . $this->lng->txt('tst_password_form')
103 );
104
105 $this->tpl->setVariable(
106 $this->parent_gui->getContentBlockName(),
107 $this->buildPasswordMsg() . $this->ctrl->getHTML($this->buildPasswordForm())
108 );
109 }
110
111 private function saveEnteredPasswordCmd(): void
112 {
113 $this->password_checker->setUserEnteredPassword($this->testrequest->strVal('password'));
114
115 if (!$this->password_checker->isUserEnteredPasswordCorrect()) {
116 $this->password_checker->logWrongEnteredPassword();
117 }
118
119 $this->ctrl->redirectByClass($this->getNextCommandClass(), $this->getNextCommandCmd());
120 }
121
122 private function backToInfoScreenCmd(): void
123 {
124 $this->ctrl->redirectByClass([ilRepositoryGUI::class, ilObjTestGUI::class, ilInfoScreenGUI::class]);
125 }
126
127 private function setNextCommandClass(string $next_command_class): void
128 {
129 $this->next_command_class = $next_command_class;
130 }
131
132 private function getNextCommandClass(): string
133 {
135 }
136
137 private function setNextCommandCmd(string $next_command_cmd): void
138 {
139 $this->next_command_cmd = $next_command_cmd;
140 }
141
142 private function getNextCommandCmd(): string
143 {
145 }
146}
language handling
This class represents a password property in a property form.
This class represents a property form user interface.
setNextCommandClass(string $next_command_class)
__construct(private ilCtrlInterface $ctrl, private ilGlobalTemplateInterface $tpl, private ilLanguage $lng, private ilTestPlayerAbstractGUI $parent_gui, private ilTestPasswordChecker $password_checker, private RequestDataCollector $testrequest, private GlobalScreen $global_screen)
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31