forked from mschering/groupoffice-owncloud
-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_groupoffice.php
151 lines (112 loc) · 3.7 KB
/
user_groupoffice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace OCA\groupoffice;
class User extends \OC_User_Backend
{
private $_user = array();
public function __construct()
{
$groupoffice_root = rtrim(\OC_Config::getValue("groupoffice_root", "/usr/share/groupoffice"), '/');
$groupoffice_config = \OC_Config::getValue("groupoffice_config");
if (!empty($groupoffice_config))
define('GO_CONFIG_FILE', $groupoffice_config);
require_once($groupoffice_root . '/GO.php');
//create group-office mount.json file
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
$mountFile = $datadir . '/mount.json';
if (!file_exists($mountFile)) {
$mountConfig = array(
'user' => array(
'all' => array(
'/$user/files/Groupoffice' =>
array(
'class' => '\OC\Files\Storage\Groupoffice',
'options' => array(
'user' => '$user'
),
'priority' => 150
),
)
)
);
file_put_contents($mountFile, json_encode($mountConfig));
}
}
public function deleteUser($uid)
{
// Can't delete user
return false;
}
public function setPassword($uid, $password)
{
// We can't change user password
return false;
}
public function checkPassword($uid, $password)
{
$this->_user[$uid] = \GO::session()->login($uid, $password, false);
if (!$this->_user[$uid]) {
return false;
} else {
//workaround bug in ownCloud
$cache = \OC_User::getHome($uid) . '/cache';
if (!is_dir($cache))
mkdir($cache, 0755, true);
return $uid;
}
}
private function _getUser($username)
{
if (!isset($this->_user[$username])) {
$this->_user[$username] = \GO_Base_Model_User::model()->findSingleByAttribute('username', $username);
}
return $this->_user[$username];
}
public function userExists($uid)
{
return $this->_getUser($uid) != false;
}
public function hasUserListings()
{
return true;
}
public function getUsers($search = '', $limit = -1, $offset = 0)
{
$returnArray = array();
$fp = \GO_Base_Db_FindParams::newInstance()
->start($offset)
->searchQuery('%' . $search . '%');
if ($limit > 0)
$fp->limit($limit);
$stmt = \GO_Base_Model_User::model()->find($fp);
foreach ($stmt as $user) {
$returnArray[] = $user->username;
}
return $returnArray;
}
public function getHome($uid)
{
$home = new \GO_Base_Fs_Folder(\GO::config()->file_storage_path . 'owncloud/' . $this->_getUser($uid)->username);
$home->create();
return $home->path();
}
public function getDisplayName($uid)
{
return $this->_getUser($uid)->name;
}
public function countUsers()
{
$findParams = \GO_Base_Db_FindParams::newInstance()
->single()
->select('count(*) as total');
$record = \GO_Base_Model_User::model()->find($findParams);
return $record->total;
}
public function implementsActions($actions)
{
return (bool)((OC_USER_BACKEND_CHECK_PASSWORD
| OC_USER_BACKEND_GET_HOME
| OC_USER_BACKEND_GET_DISPLAYNAME
| OC_USER_BACKEND_COUNT_USERS)
& $actions);
}
}