Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/xaction/PhabricatorAuthFactorProviderDuoHostnameTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorAuthFactorProviderDuoHostnameTransaction
4
extends PhabricatorAuthFactorProviderTransactionType {
5
6
const TRANSACTIONTYPE = 'duo.hostname';
7
8
public function generateOldValue($object) {
9
$key = PhabricatorDuoAuthFactor::PROP_HOSTNAME;
10
return $object->getAuthFactorProviderProperty($key);
11
}
12
13
public function applyInternalEffects($object, $value) {
14
$key = PhabricatorDuoAuthFactor::PROP_HOSTNAME;
15
$object->setAuthFactorProviderProperty($key, $value);
16
}
17
18
public function getTitle() {
19
return pht(
20
'%s changed the hostname for this provider from %s to %s.',
21
$this->renderAuthor(),
22
$this->renderOldValue(),
23
$this->renderNewValue());
24
}
25
26
public function validateTransactions($object, array $xactions) {
27
$errors = array();
28
29
if (!$this->isDuoProvider($object)) {
30
return $errors;
31
}
32
33
$old_value = $this->generateOldValue($object);
34
if ($this->isEmptyTextTransaction($old_value, $xactions)) {
35
$errors[] = $this->newRequiredError(
36
pht('Duo providers must have an API hostname.'));
37
}
38
39
foreach ($xactions as $xaction) {
40
$new_value = $xaction->getNewValue();
41
42
if (!strlen($new_value)) {
43
continue;
44
}
45
46
if ($new_value === $old_value) {
47
continue;
48
}
49
50
try {
51
PhabricatorDuoAuthFactor::requireDuoAPIHostname($new_value);
52
} catch (Exception $ex) {
53
$errors[] = $this->newInvalidError(
54
$ex->getMessage(),
55
$xaction);
56
continue;
57
}
58
}
59
60
return $errors;
61
}
62
63
}
64
65