Skip to content

Commit d4fc829

Browse files
committed
Store user_webdavauth users in DB + code cleanup
This commit introduces the storing of user_webdavauth users in the database which is a pre-requisite of #12620. Furthermore, I refactored the code and removed deprecated code, as a little gimmick I added unit tests for the backend. Conflicts: lib/private/server.php Conflicts: apps/user_webdavauth/appinfo/app.php apps/user_webdavauth/user_webdavauth.php
1 parent e08ebe8 commit d4fc829

10 files changed

Lines changed: 838 additions & 60 deletions

File tree

apps/user_webdavauth/appinfo/app.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @author Felix Moeller <[email protected]>
44
* @author Frank Karlitschek <[email protected]>
55
* @author j-ed <[email protected]>
6+
* @author Lukas Reschke <[email protected]>
67
*
78
* @copyright Copyright (c) 2015, ownCloud, Inc.
89
* @license AGPL-3.0
@@ -20,17 +21,22 @@
2021
* along with this program. If not, see <http://www.gnu.org/licenses/>
2122
*
2223
*/
23-
require_once OC_App::getAppPath('user_webdavauth').'/user_webdavauth.php';
2424

25-
OC_APP::registerAdmin('user_webdavauth', 'settings');
25+
namespace OCA\user_webdavauth\AppInfo;
2626

27-
OC_User::registerBackend("WEBDAVAUTH");
28-
OC_User::useBackend( "WEBDAVAUTH" );
27+
use OCA\user_webdavauth\USER_WEBDAVAUTH;
28+
use OCP\Util;
2929

30-
// add settings page to navigation
31-
$entry = array(
32-
'id' => "user_webdavauth_settings",
33-
'order'=>1,
34-
'href' => OC_Helper::linkTo( "user_webdavauth", "settings.php" ),
35-
'name' => 'WEBDAVAUTH'
30+
31+
$userBackend = new USER_WEBDAVAUTH(
32+
\OC::$server->getConfig(),
33+
\OC::$server->getDb(),
34+
\OC::$server->getHTTPHelper(),
35+
\OC::$server->getLogger(),
36+
\OC::$server->getUserManager(),
37+
\OC::$SERVERROOT
3638
);
39+
\OC_User::useBackend($userBackend);
40+
41+
Util::addTranslations('user_webdavauth');
42+
\OC_APP::registerAdmin('user_webdavauth', 'settings');
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="ISO-8859-1" ?>
2+
<database>
3+
4+
<name>*dbname*</name>
5+
<create>true</create>
6+
<overwrite>false</overwrite>
7+
<charset>utf8</charset>
8+
9+
<table>
10+
11+
<name>*dbprefix*webdav_user_mapping</name>
12+
13+
<declaration>
14+
15+
<field>
16+
<name>uid</name>
17+
<type>text</type>
18+
<notnull>true</notnull>
19+
<length>255</length>
20+
</field>
21+
22+
<field>
23+
<name>displayname</name>
24+
<type>text</type>
25+
<notnull>false</notnull>
26+
<length>255</length>
27+
</field>
28+
29+
<index>
30+
<name>webdav_uid</name>
31+
<unique>true</unique>
32+
<field>
33+
<name>uid</name>
34+
</field>
35+
</index>
36+
37+
</declaration>
38+
39+
</table>
40+
41+
</database>

apps/user_webdavauth/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<info>
33
<id>user_webdavauth</id>
44
<name>WebDAV user backend</name>
5-
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other webserver to authenticate. It should return http 200 for right credentials and http 401 for wrong ones.
5+
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other web server to authenticate. It should return a HTTP 2xx status code for correct credentials and a 4xx or 5xx for invalid ones.
66

7-
Attention: This app is not compatible with the LDAP user and group backend. This app is not the webdav interface of ownCloud, if you don't understand what it does then do not enable it.</description>
7+
Attention: This app is not the WebDAV interface of ownCloud, if you don't understand what it does then do not enable it.</description>
88
<licence>AGPL</licence>
99
<author>Frank Karlitschek</author>
10-
<requiremin>4.93</requiremin>
10+
<requiremin>7.0</requiremin>
1111
<shipped>true</shipped>
1212
<types>
1313
<authentication/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0.1
1+
1.2.0.0

apps/user_webdavauth/settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
OCP\JSON::callCheck();
2929

3030
if(isset($_POST['webdav_url'])) {
31-
OC_CONFIG::setValue('user_webdavauth_url', strip_tags($_POST['webdav_url']));
31+
\OC::$server->getConfig()->setSystemValue('user_webdavauth_url', $_POST['webdav_url']);
3232
}
3333
}
3434

3535
// fill template
36-
$tmpl = new OC_Template( 'user_webdavauth', 'settings');
37-
$tmpl->assign( 'webdav_url', OC_Config::getValue( "user_webdavauth_url" ));
36+
$tmpl = new OC_Template('user_webdavauth', 'settings');
37+
$tmpl->assign('webdav_url', \OC::$server->getConfig()->getSystemValue('user_webdavauth_url'));
3838

3939
return $tmpl->fetchPage();
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
<?php
2+
/** @var array $_ */
3+
?>
14
<form id="webdavauth" class="section" action="#" method="post">
25
<h2><?php p($l->t('WebDAV Authentication'));?></h2>
3-
<p><label for="webdav_url"><?php p($l->t('Address:').' ');?><input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>"></label>
4-
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
5-
<input type="submit" value="<?php p($l->t('Save')); ?>" />
6-
<br /><?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP statuscodes 401 and 403 as invalid credentials, and all other responses as valid credentials.')); ?>
6+
<p>
7+
<label for="webdav_url"><?php p($l->t('Address:').' ');?>
8+
<input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>">
9+
</label>
10+
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
11+
<input type="submit" value="<?php p($l->t('Save')); ?>" />
12+
<br />
13+
<?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP status codes 2xx and 403 as valid credentials, and all other responses as invalid credentials.')); ?>
14+
</p>
715
</form>

0 commit comments

Comments
 (0)