1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Teampass - a collaborative passwords manager. |
4
|
|
|
* --- |
5
|
|
|
* This library is distributed in the hope that it will be useful, |
6
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
8
|
|
|
* --- |
9
|
|
|
* |
10
|
|
|
* @project Teampass |
11
|
|
|
* @version API |
12
|
|
|
* |
13
|
|
|
* @file UserControler.php |
14
|
|
|
* --- |
15
|
|
|
* |
16
|
|
|
* @author Nils Laumaillé ([email protected]) |
17
|
|
|
* |
18
|
|
|
* @copyright 2009-2025 Teampass.net |
19
|
|
|
* |
20
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
21
|
|
|
* --- |
22
|
|
|
* |
23
|
|
|
* @see https://www.teampass.net |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use Symfony\Component\HttpFoundation\Request AS symfonyRequest; |
27
|
|
|
|
28
|
|
|
class UserController extends BaseController |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* "/user/list" Endpoint - Get list of users |
32
|
|
|
*/ |
33
|
|
|
public function listAction() |
34
|
|
|
{ |
35
|
|
|
$request = symfonyRequest::createFromGlobals(); |
36
|
|
|
$requestMethod = $request->getMethod(); |
37
|
|
|
$strErrorDesc = $responseData = $strErrorHeader = ''; |
38
|
|
|
$arrQueryStringParams = $this->getQueryStringParams(); |
39
|
|
|
|
40
|
|
|
if (strtoupper($requestMethod) === 'GET') { |
41
|
|
|
try { |
42
|
|
|
$userModel = new UserModel(); |
43
|
|
|
|
44
|
|
|
$intLimit = 10; |
45
|
|
|
if (isset($arrQueryStringParams['limit']) === true && empty($arrQueryStringParams['limit']) === false) { |
46
|
|
|
$intLimit = $arrQueryStringParams['limit']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$arrUsers = $userModel->getUsers($intLimit); |
50
|
|
|
$responseData = json_encode($arrUsers); |
51
|
|
|
} catch (Error $e) { |
52
|
|
|
$strErrorDesc = $e->getMessage().'. Something went wrong! Please contact support.7'; |
53
|
|
|
$strErrorHeader = 'HTTP/1.1 500 Internal Server Error'; |
54
|
|
|
} |
55
|
|
|
} else { |
56
|
|
|
$strErrorDesc = 'Method not supported'; |
57
|
|
|
$strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// send output |
61
|
|
|
if (empty($strErrorDesc) === true) { |
62
|
|
|
$this->sendOutput( |
63
|
|
|
$responseData, |
64
|
|
|
['Content-Type: application/json', 'HTTP/1.1 200 OK'] |
65
|
|
|
); |
66
|
|
|
} else { |
67
|
|
|
$this->sendOutput( |
68
|
|
|
json_encode(['error' => $strErrorDesc]), |
69
|
|
|
['Content-Type: application/json', $strErrorHeader] |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |