|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BEdita, API-first content management framework |
|
4
|
|
|
* Copyright 2022 Atlas Srl, Chialab Srl |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
|
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
|
12
|
|
|
*/ |
|
13
|
|
|
namespace App\Controller\Admin; |
|
14
|
|
|
|
|
15
|
|
|
use Cake\Http\Response; |
|
16
|
|
|
use Cake\Utility\Hash; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* ExternalAuth Controller |
|
20
|
|
|
* |
|
21
|
|
|
* @property \App\Controller\Component\PropertiesComponent $Properties |
|
22
|
|
|
*/ |
|
23
|
|
|
class ExternalAuthController extends AdministrationBaseController |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritDoc |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $resourceType = 'external_auth'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritDoc |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $readonly = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritDoc |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $properties = [ |
|
39
|
|
|
'user_id' => 'string', |
|
40
|
|
|
'auth_provider_id' => 'auth_providers', |
|
41
|
|
|
'provider_username' => 'string', |
|
42
|
|
|
'params' => 'json', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Index method |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Cake\Http\Response|null |
|
49
|
|
|
*/ |
|
50
|
|
|
public function index(): ?Response |
|
51
|
|
|
{ |
|
52
|
|
|
parent::index(); |
|
53
|
|
|
$authProviders = $this->apiClient->get('/admin/auth_providers', []); |
|
54
|
|
|
$authProviders = Hash::combine((array)$authProviders, 'data.{n}.id', 'data.{n}.attributes.name'); |
|
55
|
|
|
$authProviders['-'] = '-'; |
|
56
|
|
|
$this->set('auth_providers', $authProviders); |
|
57
|
|
|
|
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Save data |
|
63
|
|
|
* |
|
64
|
|
|
* @return \Cake\Http\Response|null |
|
65
|
|
|
*/ |
|
66
|
|
|
public function save(): ?Response |
|
67
|
|
|
{ |
|
68
|
|
|
// check '-' values and set to null |
|
69
|
|
|
$data = $this->request->getData(); |
|
70
|
|
|
foreach ($data as $key => $value) { |
|
71
|
|
|
if ($value === '-') { |
|
72
|
|
|
$data[$key] = null; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return parent::save(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @inheritDoc |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $meta = []; |
|
83
|
|
|
} |
|
84
|
|
|
|