@@ -15,15 +15,30 @@ 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/sso/?action=logout&r= ' . $ encodedUrl ,
37+ $ logoutUrl ,
2338 $ this ->output
2439 );
2540 } else {
26- $ this ->output = '<a href="https:// ' .$ this -> params -> get ( ' yunohost_sso_domain ' ). ' /yunohost/sso/?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 }
0 commit comments