Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/view/PhabricatorAuthAccountView.php
12256 views
1
<?php
2
3
final class PhabricatorAuthAccountView extends AphrontView {
4
5
private $externalAccount;
6
private $provider;
7
8
public function setExternalAccount(
9
PhabricatorExternalAccount $external_account) {
10
$this->externalAccount = $external_account;
11
return $this;
12
}
13
14
public function setAuthProvider(PhabricatorAuthProvider $provider) {
15
$this->provider = $provider;
16
return $this;
17
}
18
19
public function render() {
20
$account = $this->externalAccount;
21
$provider = $this->provider;
22
23
require_celerity_resource('auth-css');
24
25
$content = array();
26
27
$dispname = $account->getDisplayName();
28
$username = $account->getUsername();
29
$realname = $account->getRealName();
30
31
$use_name = null;
32
if (strlen($dispname)) {
33
$use_name = $dispname;
34
} else if (strlen($username) && strlen($realname)) {
35
$use_name = $username.' ('.$realname.')';
36
} else if (strlen($username)) {
37
$use_name = $username;
38
} else if (strlen($realname)) {
39
$use_name = $realname;
40
}
41
42
$content[] = phutil_tag(
43
'div',
44
array(
45
'class' => 'auth-account-view-name',
46
),
47
$use_name);
48
49
if ($provider) {
50
$prov_name = pht('%s Account', $provider->getProviderName());
51
} else {
52
$prov_name = pht('"%s" Account', $account->getProviderType());
53
}
54
55
$content[] = phutil_tag(
56
'div',
57
array(
58
'class' => 'auth-account-view-provider-name',
59
),
60
array(
61
$prov_name,
62
));
63
64
$account_uri = $account->getAccountURI();
65
if (strlen($account_uri)) {
66
67
// Make sure we don't link a "javascript:" URI if a user somehow
68
// managed to get one here.
69
70
if (PhabricatorEnv::isValidRemoteURIForLink($account_uri)) {
71
$account_uri = phutil_tag(
72
'a',
73
array(
74
'href' => $account_uri,
75
'target' => '_blank',
76
'rel' => 'noreferrer',
77
),
78
$account_uri);
79
}
80
81
$content[] = phutil_tag(
82
'div',
83
array(
84
'class' => 'auth-account-view-account-uri',
85
),
86
$account_uri);
87
}
88
89
$image_file = $account->getProfileImageFile();
90
$xform = PhabricatorFileTransform::getTransformByKey(
91
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
92
$image_uri = $image_file->getURIForTransform($xform);
93
list($x, $y) = $xform->getTransformedDimensions($image_file);
94
95
$profile_image = phutil_tag(
96
'div',
97
array(
98
'class' => 'auth-account-view-profile-image',
99
'style' => 'background-image: url('.$image_uri.');',
100
));
101
102
return phutil_tag(
103
'div',
104
array(
105
'class' => 'auth-account-view',
106
),
107
array(
108
$profile_image,
109
$content,
110
));
111
}
112
113
}
114
115