ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestPasswordProtectionGUI.php
Go to the documentation of this file.
1 <?php
2 
28 {
29  public const CMD_SHOW_PASSWORD_FORM = 'showPasswordForm';
30  public const CMD_SAVE_ENTERED_PASSWORD = 'saveEnteredPassword';
31  public const CMD_BACK_TO_INFO_SCREEN = 'backToInfoScreen';
32  private \ILIAS\Test\InternalRequestService $testrequest;
33 
37  protected $ctrl;
38 
42  protected $tpl;
43 
47  protected $lng;
48 
52  protected $parentGUI;
53 
57  protected $passwordChecker;
58 
63 
67  private $nextCommandCmd;
68 
70  {
71  global $DIC;
72  $this->testrequest = $DIC->test()->internal()->request();
73  $this->ctrl = $ctrl;
74  $this->tpl = $tpl;
75  $this->lng = $lng;
76  $this->parentGUI = $parentGUI;
77  $this->passwordChecker = $passwordChecker;
78  }
79 
80  public function executeCommand()
81  {
82  $this->ctrl->saveParameter($this, 'nextCommand');
83  $nextCommand = explode('::', $this->testrequest->getNextCommand());
84  $this->setNextCommandClass($nextCommand[0]);
85  $this->setNextCommandCmd($nextCommand[1]);
86 
87  $this->ctrl->saveParameter($this->parentGUI, 'lock');
88 
89  switch ($this->ctrl->getNextClass()) {
90  default:
91 
92  $cmd = $this->ctrl->getCmd() . 'Cmd';
93  $this->$cmd();
94  }
95  }
96 
97  protected function buildPasswordMsg(): string
98  {
99  if (!$this->passwordChecker->wrongUserEnteredPasswordExist()) {
100  return '';
101  }
102 
104  $this->lng->txt('tst_password_entered_wrong_password'),
105  'failure'
106  );
107  }
108 
112  protected function buildPasswordForm(): ilPropertyFormGUI
113  {
114  $form = new ilPropertyFormGUI();
115  $form->setTitle($this->lng->txt("tst_password_form"));
116  $form->setDescription($this->lng->txt("tst_password_introduction"));
117 
118  $form->setFormAction($this->ctrl->getFormAction($this));
119  $form->addCommandButton(self::CMD_SAVE_ENTERED_PASSWORD, $this->lng->txt("submit"));
120  $form->addCommandButton(self::CMD_BACK_TO_INFO_SCREEN, $this->lng->txt("cancel"));
121 
122  $inp = new ilPasswordInputGUI($this->lng->txt("tst_password"), 'password');
123  $inp->setRequired(true);
124  $inp->setRetype(false);
125  $form->addItem($inp);
126  return $form;
127  }
128 
129  private function showPasswordFormCmd()
130  {
131  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
132  require_once 'Services/Form/classes/class.ilPasswordInputGUI.php';
133 
134  global $DIC;
135  $DIC->globalScreen()->tool()->context()->current()->getAdditionalData()->replace(
137  $this->parentGUI->getObject()->getTitle() . ' - ' . $this->lng->txt('tst_password_form')
138  );
139 
140  $msg = $this->buildPasswordMsg();
141  $form = $this->buildPasswordForm();
142 
143  $this->tpl->setVariable(
144  $this->parentGUI->getContentBlockName(),
145  $msg . $this->ctrl->getHTML($form)
146  );
147  }
148 
149  private function saveEnteredPasswordCmd()
150  {
151  $this->passwordChecker->setUserEnteredPassword($_POST["password"]);
152 
153  if (!$this->passwordChecker->isUserEnteredPasswordCorrect()) {
154  $this->passwordChecker->logWrongEnteredPassword();
155  }
156 
157  $this->ctrl->redirectByClass($this->getNextCommandClass(), $this->getNextCommandCmd());
158  }
159 
160  private function backToInfoScreenCmd()
161  {
162  $this->ctrl->redirectByClass('ilObjTestGUI', 'infoScreen');
163  }
164 
166  {
167  $this->nextCommandClass = $nextCommandClass;
168  }
169 
170  private function getNextCommandClass(): string
171  {
173  }
174 
176  {
177  $this->nextCommandCmd = $nextCommandCmd;
178  }
179 
180  private function getNextCommandCmd(): string
181  {
182  return $this->nextCommandCmd;
183  }
184 }
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilTestPlayerAbstractGUI $parentGUI, ilTestPasswordChecker $passwordChecker)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRequired(bool $a_required)
ILIAS Test InternalRequestService $testrequest
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...