|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace MikoPBX\PBXCoreREST\Lib; |
|
21
|
|
|
|
|
22
|
|
|
use MikoPBX\Common\Models\Users; |
|
23
|
|
|
use Phalcon\Di\Injectable; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class UsersManagementProcessor |
|
27
|
|
|
* |
|
28
|
|
|
* @package MikoPBX\PBXCoreREST\Lib |
|
29
|
|
|
* |
|
30
|
|
|
*/ |
|
31
|
|
|
class UsersManagementProcessor extends Injectable |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Processes Users management requests |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $request |
|
37
|
|
|
* |
|
38
|
|
|
* @return PBXApiResult An object containing the result of the API call. |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function callBack(array $request): PBXApiResult |
|
41
|
|
|
{ |
|
42
|
|
|
$res = new PBXApiResult(); |
|
43
|
|
|
$res->processor = __METHOD__; |
|
44
|
|
|
|
|
45
|
|
|
$action = $request['action']; |
|
46
|
|
|
$data = $request['data']; |
|
47
|
|
|
switch ($action) { |
|
48
|
|
|
case 'available': |
|
49
|
|
|
if (!empty($data['email'])) { |
|
50
|
|
|
$record = Users::findFirstByEmail($data['email']); |
|
51
|
|
|
if ($record) { |
|
52
|
|
|
$res->data['userId'] = $record->id; |
|
53
|
|
|
$res->data['represent'] = $record->getRepresent(); |
|
54
|
|
|
$res->data['available'] = false; |
|
55
|
|
|
} else { |
|
56
|
|
|
$res->data['available'] = true; |
|
57
|
|
|
} |
|
58
|
|
|
$res->success = true; |
|
59
|
|
|
} else { |
|
60
|
|
|
$res->messages['error'][] = 'Empty email value in POST/GET data'; |
|
61
|
|
|
} |
|
62
|
|
|
break; |
|
63
|
|
|
default: |
|
64
|
|
|
$res->messages['error'][] = "Unknown action - $action in " . __CLASS__; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$res->function = $action; |
|
68
|
|
|
|
|
69
|
|
|
return $res; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
} |