|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package midcom |
|
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Wrapper for acces denied page responses |
|
11
|
|
|
* |
|
12
|
|
|
* @package midcom |
|
13
|
|
|
*/ |
|
14
|
|
|
class midcom_response_accessdenied extends midcom_response_login |
|
15
|
|
|
{ |
|
16
|
|
|
private $message; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param string $message The message to show to the user. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(string $message) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->message = $message; |
|
24
|
|
|
parent::__construct(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* This will display the error message and appends the login form below it |
|
29
|
|
|
* |
|
30
|
|
|
* The login message shown depends on the current state: |
|
31
|
|
|
* - If an authentication attempt was done but failed, an appropriated wrong user/password |
|
32
|
|
|
* message is shown. |
|
33
|
|
|
* - If the user is authenticated, a note that he might have to switch to a user with more |
|
34
|
|
|
* privileges is shown. |
|
35
|
|
|
* - Otherwise, no message is shown. |
|
36
|
|
|
* |
|
37
|
|
|
* If the style element <i>midcom_services_auth_access_denied</i> is defined, it will be shown |
|
38
|
|
|
* instead of the default error page. The following variables will be available in the local |
|
39
|
|
|
* scope: |
|
40
|
|
|
* |
|
41
|
|
|
* $title contains the localized title of the page, based on the 'access denied' string ID of |
|
42
|
|
|
* the main MidCOM L10n DB. $message will contain the notification what went wrong and |
|
43
|
|
|
* $login_warning will notify the user of a failed login. The latter will either be empty |
|
44
|
|
|
* or enclosed in a paragraph with the CSS ID 'login_warning'. |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function render() : string |
|
47
|
|
|
{ |
|
48
|
|
|
// Determine login message |
|
49
|
|
|
$login_warning = ''; |
|
50
|
|
|
if (midcom::get()->auth->user !== null) { |
|
51
|
|
|
// The user has insufficient privileges |
|
52
|
|
|
$login_warning = midcom::get()->i18n->get_string('login message - insufficient privileges', 'midcom'); |
|
53
|
|
|
} elseif (midcom::get()->auth->has_login_data()) { |
|
54
|
|
|
$login_warning = midcom::get()->i18n->get_string('login message - user or password wrong', 'midcom'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$title = midcom::get()->i18n->get_string('access denied', 'midcom'); |
|
58
|
|
|
|
|
59
|
|
|
midcom::get()->style->data['midcom_services_auth_access_denied_message'] = $this->message; |
|
60
|
|
|
midcom::get()->style->data['midcom_services_auth_access_denied_title'] = $title; |
|
61
|
|
|
midcom::get()->style->data['midcom_services_auth_access_denied_login_warning'] = $login_warning; |
|
62
|
|
|
|
|
63
|
|
|
ob_start(); |
|
64
|
|
|
midcom::get()->style->show_midcom('midcom_services_auth_access_denied'); |
|
65
|
|
|
return ob_get_clean(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|