@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorAuthSetExternalController
4 extends PhabricatorAuthController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8
9 $configs = id(new PhabricatorAuthProviderConfigQuery())
10 ->setViewer($viewer)
11 ->withIsEnabled(true)
12 ->execute();
13
14 $linkable = array();
15 foreach ($configs as $config) {
16 if (!$config->getShouldAllowLink()) {
17 continue;
18 }
19
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;
25 }
26
27 $linkable[] = $config;
28 }
29
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('/');
38 }
39
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());
50 }
51
52 $remarkup_view = new PHUIRemarkupView($viewer, $text);
53 $remarkup_view = phutil_tag(
54 'div',
55 array(
56 'class' => 'phui-object-box-instructions',
57 ),
58 $remarkup_view);
59
60 PhabricatorCookies::setClientIDCookie($request);
61
62 $view = array();
63 foreach ($configs as $config) {
64 $provider = $config->getProvider();
65
66 $form = $provider->buildLinkForm($this);
67
68 if ($provider->isLoginFormAButton()) {
69 require_celerity_resource('auth-css');
70 $form = phutil_tag(
71 'div',
72 array(
73 'class' => 'phabricator-link-button pl',
74 ),
75 $form);
76 }
77
78 $view[] = $form;
79 }
80
81 $form = id(new AphrontFormView())
82 ->setViewer($viewer)
83 ->appendControl(
84 id(new AphrontFormSubmitControl())
85 ->addCancelButton('/', pht('Skip This Step')));
86
87 $header = id(new PHUIHeaderView())
88 ->setHeader(pht('Link External Account'));
89
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);
97
98 $main_view = id(new PHUITwoColumnView())
99 ->setFooter($box);
100
101 $crumbs = $this->buildApplicationCrumbs()
102 ->addTextCrumb(pht('Link External Account'))
103 ->setBorder(true);
104
105 return $this->newPage()
106 ->setTitle(pht('Link External Account'))
107 ->setCrumbs($crumbs)
108 ->appendChild($main_view);
109 }
110
111}