ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestPasswordChecker.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
32  protected $rbacsystem;
33 
37  protected $user;
38 
42  protected $testOBJ;
43 
47  protected $lng;
48 
50  {
51  $this->rbacsystem = $rbacsystem;
52  $this->user = $user;
53  $this->testOBJ = $testOBJ;
54  $this->lng = $lng;
55  }
56 
58  {
59  return (
60  $this->isTestPasswordEnabled()
61  && !$this->isPrivilegedParticipant()
62  && !$this->isUserEnteredPasswordCorrect()
63  );
64  }
65 
66  protected function isTestPasswordEnabled(): bool
67  {
68  return $this->testOBJ->getPassword() !== null;
69  }
70 
71  protected function isPrivilegedParticipant(): bool
72  {
73  return $this->rbacsystem->checkAccess('write', $this->testOBJ->getRefId());
74  }
75 
76  public function wrongUserEnteredPasswordExist(): bool
77  {
78  if ($this->getUserEnteredPassword() && $this->getUserEnteredPassword() === '') {
79  return false;
80  }
81 
82  return !$this->isUserEnteredPasswordCorrect();
83  }
84 
85  public function isUserEnteredPasswordCorrect(): bool
86  {
87  return $this->getUserEnteredPassword() == $this->testOBJ->getPassword();
88  }
89 
90  public function setUserEnteredPassword($enteredPassword)
91  {
92  ilSession::set($this->buildSessionKey(), $enteredPassword);
93  }
94 
95  protected function getUserEnteredPassword()
96  {
97  return ilSession::get($this->buildSessionKey());
98  }
99 
100  protected function buildSessionKey(): string
101  {
102  return 'tst_password_' . $this->testOBJ->getTestId();
103  }
104 
105  public function logWrongEnteredPassword()
106  {
108  return;
109  }
110 
112  $this->user->getId(),
113  $this->testOBJ->getId(),
115  null,
116  null,
117  true,
118  $this->testOBJ->getRefId()
119  );
120  }
121 
122  protected function getWrongEnteredPasswordLogMsg(): string
123  {
124  return $this->lng->txtlng(
125  'assessment',
126  'log_wrong_test_password_entered',
128  );
129  }
130 }
static get(string $a_var)
static _addLog( $user_id, $object_id, $logtext, $question_id=0, $original_id=0, $test_only=false, $test_ref_id=0)
Add an assessment log entry.
__construct(ilRbacSystem $rbacsystem, ilObjUser $user, ilObjTest $testOBJ, ilLanguage $lng)
setUserEnteredPassword($enteredPassword)
static set(string $a_var, $a_val)
Set a value.