ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestPasswordChecker.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
5
13{
17 protected $rbacsystem;
18
22 protected $user;
23
27 protected $testOBJ;
28
32 protected $lng;
33
35 {
36 $this->rbacsystem = $rbacsystem;
37 $this->user = $user;
38 $this->testOBJ = $testOBJ;
39 $this->lng = $lng;
40
41 $this->initSession();
42 }
43
45 {
46 if (!$this->isTestPasswordEnabled()) {
47 return false;
48 }
49
50 if ($this->isPrivilegedParticipant()) {
51 return false;
52 }
53
54 if ($this->isUserEnteredPasswordCorrect()) {
55 return false;
56 }
57
58 return true;
59 }
60
61 protected function isTestPasswordEnabled()
62 {
63 return strlen($this->testOBJ->getPassword());
64 }
65
66 protected function isPrivilegedParticipant()
67 {
68 return $this->rbacsystem->checkAccess('write', $this->testOBJ->getRefId());
69 }
70
72 {
73 if (!strlen($this->getUserEnteredPassword())) {
74 return false;
75 }
76
77 return !$this->isUserEnteredPasswordCorrect();
78 }
79
81 {
82 return $this->getUserEnteredPassword() == $this->testOBJ->getPassword();
83 }
84
85 public function setUserEnteredPassword($enteredPassword)
86 {
87 $_SESSION[$this->buildSessionKey()] = $enteredPassword;
88 }
89
90 protected function getUserEnteredPassword()
91 {
92 return $_SESSION[$this->buildSessionKey()];
93 }
94
95 protected function initSession()
96 {
97 if (!isset($_SESSION[$this->buildSessionKey()])) {
98 $_SESSION[$this->buildSessionKey()] = null;
99 }
100 }
101
102 protected function buildSessionKey()
103 {
104 return 'tst_password_' . $this->testOBJ->getTestId();
105 }
106
107 public function logWrongEnteredPassword()
108 {
110 return;
111 }
112
114 $this->user->getId(),
115 $this->testOBJ->getId(),
116 $this->getWrongEnteredPasswordLogMsg(),
117 null,
118 null,
119 true,
120 $this->testOBJ->getRefId()
121 );
122 }
123
124 protected function getWrongEnteredPasswordLogMsg()
125 {
126 return $this->lng->txtlng(
127 'assessment',
128 'log_wrong_test_password_entered',
130 );
131 }
132}
user()
Definition: user.php:4
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
language handling
static _addLog($user_id, $object_id, $logtext, $question_id="", $original_id="", $test_only=false, $test_ref_id=null)
Add an assessment log entry.
static _getLogLanguage()
retrieve the log language for assessment logging
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
__construct(ilRbacSystem $rbacsystem, ilObjUser $user, ilObjTest $testOBJ, ilLanguage $lng)
setUserEnteredPassword($enteredPassword)