Skip to content

Commit 78a2e95

Browse files
committed
feat(ssologin): backward compatibility with YunoHost 11
1 parent bc73d20 commit 78a2e95

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

actions/LoginAction__.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,32 @@ public function run()
1515
$incomingUrl = (empty($_SERVER['HTTPS']) ? 'http' : 'https').
1616
"://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
1717
$encodedUrl = base64_encode($incomingUrl);
18+
if (!file_exists('files/yunohost_version')) {
19+
exec('dpkg-query --show --showformat=\'${Version}\' yunohost > files/yunohost_version');
20+
}
21+
$yunohostVersion = file_get_contents('files/yunohost_version');
22+
$majorYunohostVersion = explode('.', $yunohostVersion)[0] ?? '';
23+
// we default on current stable Yunohost's version urls
24+
$loginUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/login?r='.$encodedUrl;
25+
$logoutUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/portalapi/logout?referer_redirect';
26+
;
27+
if ($majorYunohostVersion == '11') {
28+
// backward compatibility
29+
$loginUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?r='.$encodedUrl;
30+
$logoutUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?action=logout&r='.$encodedUrl;
31+
}
32+
1833
$authController = $this->getService(AuthController::class);
1934
if ($authController->getLoggedUser()) {
2035
$this->output = preg_replace(
2136
'~"https?://.*action=logout"~Ui',
22-
'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/portalapi/logout?referer_redirect',
37+
$logoutUrl,
2338
$this->output
2439
);
2540
} else {
26-
$this->output = '<a href="https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/login?r='.$encodedUrl.'" class="btn btn-default btn->
41+
$this->output = '<a href="''.$loginUrl.'" class="btn btn-default btn->
2742
<i class="glyphicon glyphicon-user"></i> '._t('LOGIN_LOGIN').'</a>';
2843
}
2944
}
3045
}
31-
}
46+
}

0 commit comments

Comments
 (0)