|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Canvas\Http\Response; |
|
8
|
|
|
use Canvas\Models\AppsKeys; |
|
9
|
|
|
use Phalcon\Http\RequestInterface; |
|
10
|
|
|
use Phalcon\Mvc\ModelInterface; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class CompaniesController. |
|
14
|
|
|
* |
|
15
|
|
|
* @package Canvas\Api\Controllers |
|
16
|
|
|
* |
|
17
|
|
|
* @property Users $userData |
|
18
|
|
|
* @property Request $request |
|
19
|
|
|
*/ |
|
20
|
|
|
class AppsKeysController extends BaseController |
|
21
|
|
|
{ |
|
22
|
|
|
/* |
|
23
|
|
|
* fields we accept to create |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $createFields = [ |
|
28
|
|
|
'client_id', |
|
29
|
|
|
'client_secret_id', |
|
30
|
|
|
'apps_id', |
|
31
|
|
|
'users_id', |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/* |
|
35
|
|
|
* fields we accept to create |
|
36
|
|
|
* |
|
37
|
|
|
* @var array |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $updateFields = [ |
|
40
|
|
|
'last_used_date', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* set objects. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function onConstruct() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->model = new AppsKeys(); |
|
|
|
|
|
|
51
|
|
|
$this->model->users_id = $this->userData->getId(); |
|
52
|
|
|
$this->model->apps_id = $this->app->getId(); |
|
53
|
|
|
|
|
54
|
|
|
$this->additionalSearchFields = [ |
|
|
|
|
|
|
55
|
|
|
['apps_id', ':', $this->app->getId()], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Process the create request and trecurd the boject. |
|
61
|
|
|
* |
|
62
|
|
|
* @return ModelInterface |
|
63
|
|
|
* @throws Exception |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function processCreate(RequestInterface $request): ModelInterface |
|
66
|
|
|
{ |
|
67
|
|
|
$this->model->client_id = bin2hex(random_bytes(64)); |
|
68
|
|
|
$this->model->client_secret_id = bin2hex(random_bytes(64)); |
|
69
|
|
|
$this->model->saveOrFail(); |
|
70
|
|
|
|
|
71
|
|
|
return $this->model; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Regenerate both client id and client secret id. |
|
76
|
|
|
* |
|
77
|
|
|
* @return Response |
|
78
|
|
|
*/ |
|
79
|
|
|
public function regenerateKeys() : Response |
|
80
|
|
|
{ |
|
81
|
|
|
$appsKeys = AppsKeys::findFirstOrFail([ |
|
82
|
|
|
'conditions' => 'users_id = ?0 and apps_id = ?1 and is_deleted = 0', |
|
83
|
|
|
'bind' => [$this->userData->getId(), $this->app->getId()] |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
$appsKeys->client_id = bin2hex(random_bytes(64)); |
|
87
|
|
|
$appsKeys->client_secret_id = bin2hex(random_bytes(64)); |
|
88
|
|
|
$appsKeys->saveOrFail(); |
|
89
|
|
|
|
|
90
|
|
|
return $this->response($appsKeys); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths