|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace flipbox\saml\core\services; |
|
5
|
|
|
|
|
6
|
|
|
use craft\base\Component; |
|
7
|
|
|
use craft\elements\User; |
|
8
|
|
|
use flipbox\saml\core\helpers\MappingHelper; |
|
9
|
|
|
|
|
10
|
|
|
class Cp extends Component |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public function getMappingFieldOptions($isIdp = true) |
|
14
|
|
|
{ |
|
15
|
|
|
$user = new User(); |
|
16
|
|
|
$options = [ |
|
17
|
|
|
[ |
|
18
|
|
|
'label' => $user->getAttributeLabel('firstName'), |
|
19
|
|
|
'value' => 'firstName', |
|
20
|
|
|
], |
|
21
|
|
|
[ |
|
22
|
|
|
'label' => $user->getAttributeLabel('lastName'), |
|
23
|
|
|
'value' => 'lastName', |
|
24
|
|
|
], |
|
25
|
|
|
[ |
|
26
|
|
|
'label' => $user->getAttributeLabel('email'), |
|
27
|
|
|
'value' => 'email', |
|
28
|
|
|
], |
|
29
|
|
|
[ |
|
30
|
|
|
'label' => $user->getAttributeLabel('username'), |
|
31
|
|
|
'value' => 'username', |
|
32
|
|
|
], |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
if ($isIdp) { |
|
36
|
|
|
array_unshift($options, [ |
|
37
|
|
|
'label' => 'N/A (using override)', |
|
38
|
|
|
'value' => '', |
|
39
|
|
|
]); |
|
40
|
|
|
$options[] = [ |
|
41
|
|
|
'label' => $user->getAttributeLabel('uid'), |
|
42
|
|
|
'value' => 'uid', |
|
43
|
|
|
]; |
|
44
|
|
|
$options[] = [ |
|
45
|
|
|
'label' => $user->getAttributeLabel('id'), |
|
46
|
|
|
'value' => 'id', |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
foreach ($user->getFieldLayout()->getFields() as $field) { |
|
51
|
|
|
if (MappingHelper::isSupportedField($field)) { |
|
52
|
|
|
$options[] = [ |
|
53
|
|
|
'label' => $field->name, |
|
54
|
|
|
'value' => $field->handle, |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $options; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getMappingAutoSuggestions() |
|
63
|
|
|
{ |
|
64
|
|
|
$user = new User(); |
|
65
|
|
|
$options = [ |
|
66
|
|
|
[ |
|
67
|
|
|
'hint' => $user->getAttributeLabel('firstName'), |
|
68
|
|
|
'name' => '{firstName}', |
|
69
|
|
|
], |
|
70
|
|
|
[ |
|
71
|
|
|
'hint' => $user->getAttributeLabel('lastName'), |
|
72
|
|
|
'name' => '{lastName}', |
|
73
|
|
|
], |
|
74
|
|
|
[ |
|
75
|
|
|
'hint' => $user->getAttributeLabel('email'), |
|
76
|
|
|
'name' => '{email}', |
|
77
|
|
|
], |
|
78
|
|
|
[ |
|
79
|
|
|
'hint' => $user->getAttributeLabel('username'), |
|
80
|
|
|
'name' => '{username}', |
|
81
|
|
|
], |
|
82
|
|
|
[ |
|
83
|
|
|
'hint' => $user->getAttributeLabel('uid'), |
|
84
|
|
|
'name' => '{uid}', |
|
85
|
|
|
], |
|
86
|
|
|
[ |
|
87
|
|
|
'hint' => $user->getAttributeLabel('id'), |
|
88
|
|
|
'name' => '{id}', |
|
89
|
|
|
], |
|
90
|
|
|
]; |
|
91
|
|
|
|
|
92
|
|
|
$contentOptions = []; |
|
93
|
|
|
foreach ($user->getFieldLayout()->getFields() as $field) { |
|
94
|
|
|
if (! MappingHelper::isSupportedField($field)) { |
|
95
|
|
|
continue; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$fieldType = get_class($field); |
|
99
|
|
|
$contentOptions[] = [ |
|
100
|
|
|
'hint' => $field->name . " ($fieldType)", |
|
101
|
|
|
'name' => '{' . $field->handle . '}', |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$return = [ |
|
106
|
|
|
[ |
|
107
|
|
|
'label' => 'Standard Fields', |
|
108
|
|
|
'data' => $options, |
|
109
|
|
|
], |
|
110
|
|
|
]; |
|
111
|
|
|
|
|
112
|
|
|
if (! empty($contentOptions)) { |
|
113
|
|
|
$return[] = [ |
|
114
|
|
|
'label' => 'Content Fields', |
|
115
|
|
|
'data' => $contentOptions, |
|
116
|
|
|
]; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $return; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|