|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: dsmrt |
|
5
|
|
|
* Date: 3/10/18 |
|
6
|
|
|
* Time: 8:40 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\saml\core\controllers\cp\view\metadata; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\helpers\UrlHelper; |
|
13
|
|
|
use flipbox\saml\core\AbstractPlugin; |
|
14
|
|
|
use flipbox\saml\core\controllers\cp\view\AbstractController; |
|
15
|
|
|
use flipbox\saml\core\records\ProviderInterface; |
|
16
|
|
|
use flipbox\saml\core\EnsureSAMLPlugin; |
|
17
|
|
|
use flipbox\saml\core\models\SettingsInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractEditController |
|
21
|
|
|
* @package flipbox\saml\core\controllers\cp\view\metadata |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractEditController extends AbstractController implements EnsureSAMLPlugin |
|
24
|
|
|
{ |
|
25
|
|
|
use VariablesTrait; |
|
26
|
|
|
|
|
27
|
|
|
const TEMPLATE_INDEX = DIRECTORY_SEPARATOR . '_cp' . DIRECTORY_SEPARATOR . 'metadata'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string|null $providerId |
|
31
|
|
|
* @return \yii\web\Response |
|
32
|
|
|
*/ |
|
33
|
|
|
public function actionIndex($providerId = null, $overwriteVariables = []) |
|
34
|
|
|
{ |
|
35
|
|
|
$variables = $this->prepVariables($providerId); |
|
36
|
|
|
$provider = $variables['provider']; |
|
37
|
|
|
|
|
38
|
|
|
$variables['title'] = Craft::t( |
|
39
|
|
|
$this->getPlugin()->getHandle(), |
|
40
|
|
|
'Edit ' . $this->getTitle($provider->getType()) |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
$variables['createType'] = $variables['remoteType']; |
|
44
|
|
|
|
|
45
|
|
|
if (isset($variables['provider']) && $variables['provider'] instanceof ProviderInterface) { |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Actions |
|
49
|
|
|
*/ |
|
50
|
|
|
$variables['actions'] = $this->getActions($variables['provider']); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$variables = array_merge($variables, $overwriteVariables); |
|
54
|
|
|
return $this->renderTemplate( |
|
55
|
|
|
$this->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'edit', |
|
56
|
|
|
$variables |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return \yii\web\Response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function actionNewIdp() |
|
64
|
|
|
{ |
|
65
|
|
|
/** @var AbstractPlugin $plugin */ |
|
66
|
|
|
$plugin = $this->getPlugin(); |
|
67
|
|
|
$providerRecord = $this->getPlugin()->getProviderRecordClass(); |
|
68
|
|
|
return $this->actionIndex(null, [ |
|
69
|
|
|
'title' => 'New ' . $this->getTitle(SettingsInterface::IDP), |
|
70
|
|
|
'createType' => SettingsInterface::IDP, |
|
71
|
|
|
'provider' => new $providerRecord([ |
|
72
|
|
|
'providerType' => SettingsInterface::IDP, |
|
73
|
|
|
]), |
|
74
|
|
|
'crumbs' => [ |
|
75
|
|
|
[ |
|
76
|
|
|
'url' => UrlHelper::cpUrl( |
|
77
|
|
|
implode( |
|
78
|
|
|
'/', |
|
79
|
|
|
[ |
|
80
|
|
|
$plugin->getHandle(), |
|
81
|
|
|
] |
|
82
|
|
|
) |
|
83
|
|
|
), |
|
84
|
|
|
'label' => $plugin->name, |
|
85
|
|
|
], |
|
86
|
|
|
[ |
|
87
|
|
|
'url' => UrlHelper::cpUrl( |
|
88
|
|
|
implode( |
|
89
|
|
|
'/', |
|
90
|
|
|
[ |
|
91
|
|
|
$plugin->getHandle(), |
|
92
|
|
|
'metadata', |
|
93
|
|
|
] |
|
94
|
|
|
) |
|
95
|
|
|
), |
|
96
|
|
|
'label' => 'Provider List', |
|
97
|
|
|
], |
|
98
|
|
|
[ |
|
99
|
|
|
'url' => UrlHelper::cpUrl( |
|
100
|
|
|
implode( |
|
101
|
|
|
'/', |
|
102
|
|
|
[ |
|
103
|
|
|
$plugin->getHandle(), |
|
104
|
|
|
'metadata', |
|
105
|
|
|
'new-idp', |
|
106
|
|
|
] |
|
107
|
|
|
) |
|
108
|
|
|
), |
|
109
|
|
|
'label' => 'New IDP', |
|
110
|
|
|
], |
|
111
|
|
|
], |
|
112
|
|
|
]); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return \yii\web\Response |
|
117
|
|
|
*/ |
|
118
|
|
|
public function actionNewSp() |
|
119
|
|
|
{ |
|
120
|
|
|
/** @var AbstractPlugin $plugin */ |
|
121
|
|
|
$plugin = $this->getPlugin(); |
|
122
|
|
|
$providerRecord = $this->getPlugin()->getProviderRecordClass(); |
|
123
|
|
|
return $this->actionIndex(null, [ |
|
124
|
|
|
'title' => 'New ' . $this->getTitle(SettingsInterface::SP), |
|
125
|
|
|
'createType' => SettingsInterface::SP, |
|
126
|
|
|
'provider' => new $providerRecord([ |
|
127
|
|
|
'providerType' => SettingsInterface::SP, |
|
128
|
|
|
]), |
|
129
|
|
|
'crumbs' => [ |
|
130
|
|
|
[ |
|
131
|
|
|
'url' => UrlHelper::cpUrl( |
|
132
|
|
|
implode( |
|
133
|
|
|
'/', |
|
134
|
|
|
[ |
|
135
|
|
|
$plugin->getHandle(), |
|
136
|
|
|
] |
|
137
|
|
|
) |
|
138
|
|
|
), |
|
139
|
|
|
'label' => $plugin->name, |
|
140
|
|
|
], |
|
141
|
|
|
[ |
|
142
|
|
|
'url' => UrlHelper::cpUrl( |
|
143
|
|
|
implode( |
|
144
|
|
|
'/', |
|
145
|
|
|
[ |
|
146
|
|
|
$plugin->getHandle(), |
|
147
|
|
|
'metadata', |
|
148
|
|
|
] |
|
149
|
|
|
) |
|
150
|
|
|
), |
|
151
|
|
|
'label' => 'Provider List', |
|
152
|
|
|
], |
|
153
|
|
|
[ |
|
154
|
|
|
'url' => UrlHelper::cpUrl( |
|
155
|
|
|
implode( |
|
156
|
|
|
'/', |
|
157
|
|
|
[ |
|
158
|
|
|
$plugin->getHandle(), |
|
159
|
|
|
'metadata', |
|
160
|
|
|
'new-sp', |
|
161
|
|
|
] |
|
162
|
|
|
) |
|
163
|
|
|
), |
|
164
|
|
|
'label' => 'New SP', |
|
165
|
|
|
], |
|
166
|
|
|
], |
|
167
|
|
|
]); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return \yii\web\Response |
|
172
|
|
|
*/ |
|
173
|
|
|
public function actionMyProvider() |
|
174
|
|
|
{ |
|
175
|
|
|
$provider = $this->getPlugin()->getProvider()->findOwn(); |
|
176
|
|
|
$variables = $this->prepVariables( |
|
177
|
|
|
$provider ? $provider : null |
|
178
|
|
|
); |
|
179
|
|
|
|
|
180
|
|
|
if ($provider) { |
|
181
|
|
|
$variables['provider'] = $provider; |
|
182
|
|
|
|
|
183
|
|
|
$variables = array_merge( |
|
184
|
|
|
$variables, |
|
185
|
|
|
$this->addUrls($provider) |
|
186
|
|
|
); |
|
187
|
|
|
} else { |
|
188
|
|
|
$provider = $variables['provider']; |
|
189
|
|
|
$variables['provider']->entityId = $this->getPlugin()->getSettings()->getEntityId(); |
|
190
|
|
|
$variables['provider']->providerType = $this->getPlugin()->getMyType(); |
|
191
|
|
|
$variables['provider']->label = 'My Provider'; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Actions |
|
196
|
|
|
*/ |
|
197
|
|
|
$variables['actions'] = $this->getActions($provider); |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Edit Title |
|
201
|
|
|
*/ |
|
202
|
|
|
$variables['title'] = Craft::t( |
|
203
|
|
|
$this->getPlugin()->getHandle(), |
|
204
|
|
|
'My Provider (' . strtoupper($variables['provider']->providerType) . ')' |
|
205
|
|
|
); |
|
206
|
|
|
|
|
207
|
|
|
$variables['createType'] = $variables['myType']; |
|
208
|
|
|
|
|
209
|
|
|
return $this->renderTemplate( |
|
210
|
|
|
$this->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'edit', |
|
211
|
|
|
$variables |
|
212
|
|
|
); |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|