Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/PhabricatorAuthLinkController.php
12256 views
1
<?php
2
3
final class PhabricatorAuthLinkController
4
extends PhabricatorAuthController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
$action = $request->getURIData('action');
9
10
$id = $request->getURIData('id');
11
12
$config = id(new PhabricatorAuthProviderConfigQuery())
13
->setViewer($viewer)
14
->withIDs(array($id))
15
->withIsEnabled(true)
16
->executeOne();
17
if (!$config) {
18
return new Aphront404Response();
19
}
20
21
$provider = $config->getProvider();
22
23
switch ($action) {
24
case 'link':
25
if (!$provider->shouldAllowAccountLink()) {
26
return $this->renderErrorPage(
27
pht('Account Not Linkable'),
28
array(
29
pht('This provider is not configured to allow linking.'),
30
));
31
}
32
break;
33
case 'refresh':
34
if (!$provider->shouldAllowAccountRefresh()) {
35
return $this->renderErrorPage(
36
pht('Account Not Refreshable'),
37
array(
38
pht('This provider does not allow refreshing.'),
39
));
40
}
41
break;
42
default:
43
return new Aphront400Response();
44
}
45
46
$accounts = id(new PhabricatorExternalAccountQuery())
47
->setViewer($viewer)
48
->withUserPHIDs(array($viewer->getPHID()))
49
->withProviderConfigPHIDs(array($config->getPHID()))
50
->execute();
51
52
switch ($action) {
53
case 'link':
54
if ($accounts) {
55
return $this->renderErrorPage(
56
pht('Account Already Linked'),
57
array(
58
pht(
59
'Your account is already linked to an external account for '.
60
'this provider.'),
61
));
62
}
63
break;
64
case 'refresh':
65
if (!$accounts) {
66
return $this->renderErrorPage(
67
pht('No Account Linked'),
68
array(
69
pht(
70
'You do not have a linked account on this provider, and thus '.
71
'can not refresh it.'),
72
));
73
}
74
break;
75
default:
76
return new Aphront400Response();
77
}
78
79
$panel_uri = '/settings/panel/external/';
80
81
PhabricatorCookies::setClientIDCookie($request);
82
83
switch ($action) {
84
case 'link':
85
$form = $provider->buildLinkForm($this);
86
break;
87
case 'refresh':
88
$form = $provider->buildRefreshForm($this);
89
break;
90
default:
91
return new Aphront400Response();
92
}
93
94
if ($provider->isLoginFormAButton()) {
95
require_celerity_resource('auth-css');
96
$form = phutil_tag(
97
'div',
98
array(
99
'class' => 'phabricator-link-button pl',
100
),
101
$form);
102
}
103
104
switch ($action) {
105
case 'link':
106
$name = pht('Link Account');
107
$title = pht('Link %s Account', $provider->getProviderName());
108
break;
109
case 'refresh':
110
$name = pht('Refresh Account');
111
$title = pht('Refresh %s Account', $provider->getProviderName());
112
break;
113
default:
114
return new Aphront400Response();
115
}
116
117
$crumbs = $this->buildApplicationCrumbs();
118
$crumbs->addTextCrumb(pht('Link Account'), $panel_uri);
119
$crumbs->addTextCrumb($provider->getProviderName($name));
120
$crumbs->setBorder(true);
121
122
return $this->newPage()
123
->setTitle($title)
124
->setCrumbs($crumbs)
125
->appendChild($form);
126
}
127
128
}
129
130