blob: 8873b121298066389fa1aff025ac03743080c74e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
class Page_Main extends Page
{
protected function doPreprocess()
{
User::load();
}
protected function doRender()
{
Render::addTemplate('main/_page');
if (!User::isLoggedIn()) {
// Guest
Render::addTemplate('main/guest', array('prefix' => CONFIG_PREFIX));
return;
}
// Logged in user --
if (User::isLocalOnly()) {
// Local test account
$this->renderLocalAccount();
return;
}
if (!User::isShibbolethAuth()) {
// Should not be possible
Message::addError('Sie sind nicht korrekt authentifiziert. Bitte melden Sie sich erneut an.');
Session::delete();
return;
}
// --- Below here we know the user via shibboleth
if (User::isInDatabase()) {
// User is also in DB, so he signed up for the service
$this->renderShibbolethRegistered();
return;
}
if (!User::isTutor()) {
return;
}
// User is not in DB, so he might want so sign up for the service - see if conditions are met
if (User::getOrganization() !== false) {
// Organization is known, show signup form
$this->renderShibbolethUnregistered();
return;
}
// Nothing we can do here, show error message :-(
if (User::getRemoteOrganizationId() !== false) {
// Organization is not known, see if we at least have an idea
Message::addWarning('Ihre Hochschule/Einrichtung {{0}} ist leider nicht bekannt. Bitte kontaktieren Sie den Support.', User::getRemoteOrganizationId());
} else {
// No idea where the user is coming from
Message::addError('Ihr IdP sendet leider keine Informationen über Ihre Hochschul-/Einrichtungszugehörigkeit');
}
}
private function renderShibbolethRegistered()
{
Render::addTemplate('main/logged-in');
}
private function renderShibbolethUnregistered()
{
$data = User::getData();
$data['organization'] = User::getOrganizationName();
// Shoe testacc merge form if organization has test accounts
$res = Database::queryFirst('SELECT Count(*) as cnt FROM user WHERE organizationid = :oid', array(
'oid' => User::getOrganizationId()
));
if ($res !== false && $res['cnt'] > 0) {
$data['testacc'] = true;
$mail = trim(User::getMail());
if (!empty($mail)) {
$existing = Database::queryFirst('SELECT userid FROM user WHERE email = :email LIMIT 1', array(
'email' => $mail
));
if ($existing !== false) {
$data['testlogin'] = $existing['userid'];
}
}
}
Render::addTemplate('main/deploy', $data);
}
private function renderLocalAccount()
{
$data = User::getData();
$data['organization'] = User::getOrganizationName();
Render::addTemplate('main/logged-in-testacc', $data);
}
}
|