blob: ea8935c9995b5c3bd1b895d305e13952e5e553fa (
plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
<?php
/**
* login.php - login
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author André Noack <noack@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class LoginController extends AuthenticatedController
{
protected $allow_nobody = true;
public function __construct(\Trails\Dispatcher $dispatcher)
{
Config::get()->USER_VISIBILITY_CHECK = false;
parent::__construct($dispatcher);
}
public function index_action(): void
{
if (User::findCurrent()) {
$this->redirect(URLHelper::getURL('dispatch.php/start'));
return;
}
if (Request::isXhr()) {
if (Request::isDialog()) {
$this->relocate(URLHelper::getURL($_SERVER['REQUEST_URI']));
return;
}
throw new AccessDeniedException();
}
if (Request::submitted('user_config_submitted')) {
CSRFProtection::verifyUnsafeRequest();
if (Request::submitted('unset_contrast')) {
$_SESSION['contrast'] = 0;
$this->redirect('login/index'); //we're too late to remove the high contrast mode, so we reload the page
return;
}
if (Request::submitted('set_contrast')) {
$_SESSION['contrast'] = 1;
}
foreach (array_keys($GLOBALS['INSTALLED_LANGUAGES']) as $language_key) {
if (Request::submitted('set_language_' . $language_key)) {
$_SESSION['forced_language'] = $language_key;
$_SESSION['_language'] = $language_key;
init_i18n($_SESSION['_language']);
}
}
if (!empty($_SESSION['contrast'])) {
\PageLayout::addStylesheet('accessibility.css');
}
}
if (Request::isPost()) {
CSRFProtection::verifyUnsafeRequest();
$check_auth = StudipAuthAbstract::CheckAuthentication(
Request::get('loginname'),
Request::get('password')
);
if ($check_auth['uid']) {
$uid = $check_auth['uid'];
if (
isset($check_auth['need_email_activation'])
&& $check_auth['need_email_activation'] === $uid
) {
$this->need_email_activation = $uid;
$_SESSION['semi_logged_in'] = $uid;
$this->redirect('login/activate_email', ['uid' => $uid]);
return;
} else {
auth()->setAuthenticatedUser($check_auth['user']);
Metrics::increment('core.login.succeeded');
sess()->regenerateId(['auth', '_language', 'phpCAS', 'contrast', 'redirect_after_login']);
if (isset($_SESSION['redirect_after_login'] )) {
$this->redirect($_SESSION['redirect_after_login']);
return;
}
$this->redirect('start/index');
return;
}
} else {
Metrics::increment('core.login.failed');
$this->error_msg = $check_auth['error'];
}
}
$this->has_login_error = false;
if ($this->error_msg) {
PageLayout::postException(_('Bei der Anmeldung trat ein Fehler auf!'), $this->error_msg);
$this->has_login_error = true;
}
$this->uname = $this->auth['uname'] ?? Request::username('loginname');
$this->self_registration_activated = Config::get()->getValue('ENABLE_SELF_REGISTRATION');
$this->news_entries = [];
if (Config::get()->getValue('LOGIN_NEWS_VISIBILITY')) {
$news_entries = StudipNews::GetNewsByRange('login', true);
$this->news_entries = array_values($news_entries);
}
$this->faq_entries = [];
if (Config::get()->getValue('LOGIN_FAQ_VISIBILITY')) {
$this->faq_entries = LoginFaq::findBySQL("1 ORDER BY `faq_id`");
}
PageLayout::setHelpKeyword('Basis.AnmeldungLogin');
PageLayout::disableSidebar();
PageLayout::setBodyElementId('login');
}
public function activate_email_action(): void
{
PageLayout::setTitle(_('E-Mail Aktivierung'));
$uid = Request::option('uid');
$user = User::find($uid);
if (!$user) {
throw new \Trails\Exception(400);
}
if (Request::get('key')) {
$key = $user->validation_key;
if (Request::get('key') === $key) {
$user->validation_key = '';
$user->store();
unset($_SESSION['semi_logged_in']);
PageLayout::postSuccess(_('Ihre E-Mail-Adresse wurde erfolgreich geändert.'));
$this->redirect(URLHelper::getURL('dispatch.php/start'));
} else if (!$key) {
PageLayout::postInfo(_('Ihre E-Mail-Adresse ist bereits geändert.'));
$this->redirect(URLHelper::getURL('dispatch.php/start'));
} else {
if (Request::get('key')) {
PageLayout::postError(_("Falscher Bestätigungscode."));
}
$this->mail_explain = true;
if ($_SESSION['semi_logged_in'] === Request::option('uid')) {
$this->reenter_mail = true;
} else {
PageLayout::postInfo(_('Sie können sich einloggen und sich den Bestätigungscode neu oder an eine andere E-Mail-Adresse schicken lassen.'));
$this->redirect(URLHelper::getURL('dispatch.php/start'));
}
}
// checking semi_logged_in is important to avoid abuse
} elseif (
Request::get('email1')
&& Request::get('email2')
&& $_SESSION['semi_logged_in'] === Request::option('uid')
) {
if (Request::get('email1') == Request::get('email2')) {
// change mail
$tmp_user = User::find(Request::option('uid'));
if ($tmp_user && $tmp_user->changeEmail(Request::get('email1'), true)) {
$_SESSION['semi_logged_in'] = false;
}
} else {
PageLayout::postError(_('Die eingegebenen E-Mail-Adressen stimmen nicht überein. Bitte überprüfen Sie Ihre Eingabe.'));
}
$this->mail_explain = true;
$this->reenter_mail = true;
} else {
$this->mail_explain = true;
}
}
public function privacy_info_action(): void
{
// this page must be accessible during visibility decision
Config::get()->USER_VISIBILITY_CHECK = false;
PageLayout::setTitle(_('Erläuterungen zum Datenschutz'));
}
}
|