Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/config/PhabricatorAuthNewController.php
12261 views
1
<?php
2
3
final class PhabricatorAuthNewController
4
extends PhabricatorAuthProviderConfigController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$this->requireApplicationCapability(
8
AuthManageProvidersCapability::CAPABILITY);
9
10
$viewer = $this->getViewer();
11
$cancel_uri = $this->getApplicationURI();
12
$locked_config_key = 'auth.lock-config';
13
$is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);
14
15
if ($is_locked) {
16
$message = pht(
17
'Authentication provider configuration is locked, and can not be '.
18
'changed without being unlocked. See the configuration setting %s '.
19
'for details.',
20
phutil_tag(
21
'a',
22
array(
23
'href' => '/config/edit/'.$locked_config_key,
24
),
25
$locked_config_key));
26
27
return $this->newDialog()
28
->setUser($viewer)
29
->setTitle(pht('Authentication Config Locked'))
30
->appendChild($message)
31
->addCancelButton($cancel_uri);
32
}
33
34
$providers = PhabricatorAuthProvider::getAllBaseProviders();
35
36
$configured = PhabricatorAuthProvider::getAllProviders();
37
$configured_classes = array();
38
foreach ($configured as $configured_provider) {
39
$configured_classes[get_class($configured_provider)] = true;
40
}
41
42
// Sort providers by login order, and move disabled providers to the
43
// bottom.
44
$providers = msort($providers, 'getLoginOrder');
45
$providers = array_diff_key($providers, $configured_classes) + $providers;
46
47
$menu = id(new PHUIObjectItemListView())
48
->setViewer($viewer)
49
->setBig(true)
50
->setFlush(true);
51
52
foreach ($providers as $provider_key => $provider) {
53
$provider_class = get_class($provider);
54
55
$provider_uri = id(new PhutilURI('/config/edit/'))
56
->replaceQueryParam('provider', $provider_class);
57
$provider_uri = $this->getApplicationURI($provider_uri);
58
59
$already_exists = isset($configured_classes[get_class($provider)]);
60
61
$item = id(new PHUIObjectItemView())
62
->setHeader($provider->getNameForCreate())
63
->setImageIcon($provider->newIconView())
64
->addAttribute($provider->getDescriptionForCreate());
65
66
if (!$already_exists) {
67
$item
68
->setHref($provider_uri)
69
->setClickable(true);
70
} else {
71
$item->setDisabled(true);
72
}
73
74
if ($already_exists) {
75
$messages = array();
76
$messages[] = pht('You already have a provider of this type.');
77
78
$info = id(new PHUIInfoView())
79
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
80
->setErrors($messages);
81
82
$item->appendChild($info);
83
}
84
85
$menu->addItem($item);
86
}
87
88
return $this->newDialog()
89
->setTitle(pht('Add Auth Provider'))
90
->setWidth(AphrontDialogView::WIDTH_FORM)
91
->appendChild($menu)
92
->addCancelButton($cancel_uri);
93
}
94
95
}
96
97