Skip to content

Commit 9c42f97

Browse files
committed
Refactor logout-code
1 parent 058ddd2 commit 9c42f97

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

routing/routes/routes.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
consentadmin-main:
22
path: /
33
defaults: { _controller: 'SimpleSAML\Module\consentadmin\Controller\ConsentAdmin::main' }
4+
methods: [GET]
5+
6+
consentadmin-logout:
7+
path: /logout
8+
defaults: { _controller: 'SimpleSAML\Module\consentadmin\Controller\ConsentAdmin::logout' }
9+
methods: [GET]

src/Controller/ConsentAdmin.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,31 @@ public function setConsent(Consent $consent): void
131131
/**
132132
* @param \Symfony\Component\HttpFoundation\Request $request The current request.
133133
*
134-
* @return \SimpleSAML\XHTML\Template
134+
* @return void
135135
*/
136-
public function main(Request $request): Template
136+
public function logout(Request $request): void
137137
{
138138
$authority = $this->moduleConfig->getValue('authority');
139-
140139
$as = new $this->authSimple($authority);
141140

142-
// If request is a logout request
143-
$logout = $request->get('logout');
144-
if ($logout !== null) {
145-
$returnURL = $this->moduleConfig->getValue('returnURL');
146-
$as->logout($returnURL);
147-
}
141+
$returnURL = $this->moduleConfig->getValue('returnURL');
142+
$as->logout($returnURL);
143+
}
148144

149-
$hashAttributes = $this->moduleConfig->getOptionalValue('attributes.hash', false);
150145

146+
/**
147+
* @param \Symfony\Component\HttpFoundation\Request $request The current request.
148+
*
149+
* @return \SimpleSAML\XHTML\Template
150+
*/
151+
public function main(Request $request): Template
152+
{
153+
$hashAttributes = $this->moduleConfig->getOptionalValue('attributes.hash', false);
151154
$excludeAttributes = $this->moduleConfig->getOptionalValue('attributes.exclude', []);
152155

153156
// Check if valid local session exists
157+
$authority = $this->moduleConfig->getValue('authority');
158+
$as = new $this->authSimple($authority);
154159
$as->requireAuth();
155160

156161
// Get released attributes

templates/consentadmin.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@
7777
<p>{{ '{consentAdmin:consentadmin:consentadmin_description2}'|trans|raw }}</p>
7878

7979
<h2>Logout</h2>
80-
<p><a href="/{{ baseurlpath }}module.php/consentAdmin/consentAdmin.php?logout=1">Logout</a></p>
80+
<p><a href="{{ moduleURL('consentAdmin/consentAdmin/logout'}}">Logout</a></p>
8181
8282
{% endblock %}

0 commit comments

Comments
 (0)