This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
user_groupoffice.php
150 lines (110 loc) · 3.36 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
/**
* Copyright (c) 2014 Intermesh BV
*
* This file is licensed under the Affero General Public License version 3 or
* later
*
* If you have questions write an e-mail to [email protected]
*/
namespace OCA\groupoffice;
class User extends \OC_User_Backend {
private $_user=array();
private $_groupoffice_mount;
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);
$this->_groupoffice_mount = '/'.trim(\OC_Config::getValue("groupoffice_mount", "ownCloud"),' /');
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/Group-Office'=>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);
//make sure ownCloud folder exists in Group-Office
$folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path.'users/'.$uid.$this->_groupoffice_mount);
$folder->create();
return $uid;
}
}
/**
*
* @param string $username
* @return GO\Base\Model\User
*/
private function _getUser($username){
if(!isset($this->_user[$username])){
$this->_user[$username] = \GO\Base\Model\User::model()->findSingleByAttribute('username', $username);
}
return $this->_user[$username];
}
/*
* we don´t know if a user exists without the password. so we have to return true all the time
*/
public function userExists($uid) {
return $this->_getUser($uid) != false;
}
/**
* @return bool
*/
public function hasUserListings() {
return true;
}
/*
* we don´t know the users so all we can do it return an empty array here
*/
public function getUsers($search = '', $limit = 10, $offset = 0) {
$returnArray = array();
$fp = \GO\Base\Db\FindParams::newInstance()
->limit($limit)
->start($offset)
->searchQuery($search);
$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;
}
}