mirror of
https://github.com/YunoHost-Apps/agendav_ynh.git
synced 2024-09-03 20:36:12 +02:00
Adapt HTTP auth patch to version 2.2.0
This commit is contained in:
parent
daa381103a
commit
1bdc0c0395
2 changed files with 28 additions and 68 deletions
|
@ -1,35 +0,0 @@
|
||||||
--- a/web/src/Controller/Authentication.php
|
|
||||||
+++ b/web/src/Controller/Authentication.php
|
|
||||||
@@ -83,7 +83,7 @@
|
|
||||||
* @param Application $app
|
|
||||||
* @return bool false if authentication failed, true otherwise
|
|
||||||
*/
|
|
||||||
- protected function processLogin($user, $password, Application $app)
|
|
||||||
+ public function processLogin($user, $password, Application $app)
|
|
||||||
{
|
|
||||||
$app['http.client']->setAuthentication($user, $password, $app['caldav.authmethod']);
|
|
||||||
|
|
||||||
--- a/web/app/controllers.php
|
|
||||||
+++ b/web/app/controllers.php
|
|
||||||
@@ -7,6 +7,7 @@
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
use Silex\Application;
|
|
||||||
|
|
||||||
+use AgenDAV\Controller\Authentication;
|
|
||||||
use AgenDAV\DateHelper;
|
|
||||||
|
|
||||||
// Authentication
|
|
||||||
@@ -68,6 +69,13 @@
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ if ($request->headers->get('authorization') != null) {
|
|
||||||
+ $authController = new Authentication();
|
|
||||||
+ if ($authController->processLogin($request->headers->get('PHP_AUTH_USER'), $request->headers->get('PHP_AUTH_PW'), $app)) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
if ($request->isXmlHttpRequest()) {
|
|
||||||
return new JsonResponse([], 401);
|
|
||||||
} else {
|
|
|
@ -1,25 +1,26 @@
|
||||||
--- a/web/app/controllers.php
|
--- a/web/app/controllers.php
|
||||||
+++ b/web/app/controllers.php
|
+++ b/web/app/controllers.php
|
||||||
@@ -58,14 +58,20 @@
|
@@ -58,14 +58,20 @@ $controllers->before(function(Request $request, Silex\Application $app) {
|
||||||
// processing the request
|
// processing the request
|
||||||
if ($app['session']->has('username')) {
|
if ($app['session']->has('username')) {
|
||||||
$username = $app['session']->get('username');
|
$username = $app['session']->get('username');
|
||||||
- $preferences = $app['preferences.repository']->userPreferences($username);
|
- $preferences = $app['preferences.repository']->userPreferences($username);
|
||||||
- $app['user.preferences'] = $preferences;
|
- $app['user.preferences'] = $preferences;
|
||||||
- $app['user.timezone'] = $preferences->get('timezone');
|
- $app['user.timezone'] = $preferences->get('timezone');
|
||||||
+ // Clear user session if HTTP authentication changed
|
-
|
||||||
+ if (isset($_SERVER['PHP_AUTH_USER'])
|
|
||||||
+ && $username != $_SERVER['PHP_AUTH_USER']) {
|
|
||||||
+ $app['session']->clear();
|
|
||||||
+ } else {
|
|
||||||
+ $preferences = $app['preferences.repository']->userPreferences($username);
|
|
||||||
+ $app['user.preferences'] = $preferences;
|
|
||||||
+ $app['user.timezone'] = $preferences->get('timezone');
|
|
||||||
|
|
||||||
- // Set application language
|
- // Set application language
|
||||||
- $request->setLocale($preferences->get('language'));
|
- $request->setLocale($preferences->get('language'));
|
||||||
- $app['translator']->setLocale($preferences->get('language'));
|
- $app['translator']->setLocale($preferences->get('language'));
|
||||||
- return;
|
- return;
|
||||||
|
+ // Clear user session if HTTP authentication changed
|
||||||
|
+ if (isset($_SERVER['PHP_AUTH_USER'])
|
||||||
|
+ && $username != $_SERVER['PHP_AUTH_USER']) {
|
||||||
|
+ $app['session']->clear();
|
||||||
|
+ } else {
|
||||||
|
+ $preferences = $app['preferences.repository']->userPreferences($username);
|
||||||
|
+ $app['user.preferences'] = $preferences;
|
||||||
|
+ $app['user.timezone'] = $preferences->get('timezone');
|
||||||
|
+
|
||||||
+ // Set application language
|
+ // Set application language
|
||||||
+ $request->setLocale($preferences->get('language'));
|
+ $request->setLocale($preferences->get('language'));
|
||||||
+ $app['translator']->setLocale($preferences->get('language'));
|
+ $app['translator']->setLocale($preferences->get('language'));
|
||||||
|
@ -28,31 +29,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->isXmlHttpRequest()) {
|
if ($request->isXmlHttpRequest()) {
|
||||||
|
diff --git a/web/src/Controller/Authentication.php b/web/src/Controller/Authentication.php
|
||||||
|
index deebb751..134cc9a8 100644
|
||||||
--- a/web/src/Controller/Authentication.php
|
--- a/web/src/Controller/Authentication.php
|
||||||
+++ b/web/src/Controller/Authentication.php
|
+++ b/web/src/Controller/Authentication.php
|
||||||
@@ -34,7 +34,7 @@
|
@@ -34,9 +34,14 @@ class Authentication
|
||||||
$success = false;
|
$success = false;
|
||||||
$template_vars = [];
|
$template_vars = [];
|
||||||
|
|
||||||
- if ($request->isMethod('POST')) {
|
- if ($request->isMethod('POST')) {
|
||||||
|
- $user = $request->request->get('user');
|
||||||
|
- $password = $request->request->get('password');
|
||||||
+ if ($request->isMethod('POST') || isset($_SERVER['PHP_AUTH_USER'])) {
|
+ if ($request->isMethod('POST') || isset($_SERVER['PHP_AUTH_USER'])) {
|
||||||
$user = $request->request->get('user');
|
+ if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
||||||
$password = $request->request->get('password');
|
+ $user = $_SERVER['PHP_AUTH_USER'];
|
||||||
|
+ $password = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
+ } else {
|
||||||
|
+ $user = $request->request->get('user');
|
||||||
|
+ $password = $request->request->get('password');
|
||||||
|
+ }
|
||||||
|
|
||||||
@@ -93,8 +93,14 @@
|
if (empty($user) || empty($password)) {
|
||||||
return false;
|
$template_vars['error'] = $app['translator']->trans('messages.error_empty_fields');
|
||||||
}
|
|
||||||
|
|
||||||
- $app['session']->set('username', $user);
|
|
||||||
- $app['session']->set('password', $password);
|
|
||||||
+ if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
|
||||||
+ $user = $_SERVER['PHP_AUTH_USER'];
|
|
||||||
+ $password = $_SERVER['PHP_AUTH_PW'];
|
|
||||||
+ } else {
|
|
||||||
+ $app['session']->set('username', $user);
|
|
||||||
+ $app['session']->set('password', $password);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
$principal_url = $caldav_client->getCurrentUserPrincipal();
|
|
||||||
|
|
||||||
$principals_repository = $app['principals.repository'];
|
|
Loading…
Add table
Reference in a new issue