Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / controller / PhabricatorAuthSetExternalController.php
blob2a8bbda7dfb8e7ff98e8498b1eeda2551d32ab97
1 <?php
3 final class PhabricatorAuthSetExternalController
4 extends PhabricatorAuthController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
9 $configs = id(new PhabricatorAuthProviderConfigQuery())
10 ->setViewer($viewer)
11 ->withIsEnabled(true)
12 ->execute();
14 $linkable = array();
15 foreach ($configs as $config) {
16 if (!$config->getShouldAllowLink()) {
17 continue;
20 // For now, only buttons get to appear here: for example, we can't
21 // reasonably embed an entire LDAP form into this UI.
22 $provider = $config->getProvider();
23 if (!$provider->isLoginFormAButton()) {
24 continue;
27 $linkable[] = $config;
30 if (!$linkable) {
31 return $this->newDialog()
32 ->setTitle(pht('No Linkable External Providers'))
33 ->appendParagraph(
34 pht(
35 'Currently, there are no configured external auth providers '.
36 'which you can link your account to.'))
37 ->addCancelButton('/');
40 $text = PhabricatorAuthMessage::loadMessageText(
41 $viewer,
42 PhabricatorAuthLinkMessageType::MESSAGEKEY);
43 if (!phutil_nonempty_string($text)) {
44 $text = pht(
45 'You can link your %s account to an external account to '.
46 'allow you to log in more easily in the future. To continue, choose '.
47 'an account to link below. If you prefer not to link your account, '.
48 'you can skip this step.',
49 PlatformSymbols::getPlatformServerName());
52 $remarkup_view = new PHUIRemarkupView($viewer, $text);
53 $remarkup_view = phutil_tag(
54 'div',
55 array(
56 'class' => 'phui-object-box-instructions',
58 $remarkup_view);
60 PhabricatorCookies::setClientIDCookie($request);
62 $view = array();
63 foreach ($configs as $config) {
64 $provider = $config->getProvider();
66 $form = $provider->buildLinkForm($this);
68 if ($provider->isLoginFormAButton()) {
69 require_celerity_resource('auth-css');
70 $form = phutil_tag(
71 'div',
72 array(
73 'class' => 'phabricator-link-button pl',
75 $form);
78 $view[] = $form;
81 $form = id(new AphrontFormView())
82 ->setViewer($viewer)
83 ->appendControl(
84 id(new AphrontFormSubmitControl())
85 ->addCancelButton('/', pht('Skip This Step')));
87 $header = id(new PHUIHeaderView())
88 ->setHeader(pht('Link External Account'));
90 $box = id(new PHUIObjectBoxView())
91 ->setViewer($viewer)
92 ->setHeader($header)
93 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
94 ->appendChild($remarkup_view)
95 ->appendChild($view)
96 ->appendChild($form);
98 $main_view = id(new PHUITwoColumnView())
99 ->setFooter($box);
101 $crumbs = $this->buildApplicationCrumbs()
102 ->addTextCrumb(pht('Link External Account'))
103 ->setBorder(true);
105 return $this->newPage()
106 ->setTitle(pht('Link External Account'))
107 ->setCrumbs($crumbs)
108 ->appendChild($main_view);