Path: blob/master/src/applications/auth/xaction/PhabricatorAuthFactorProviderDuoCredentialTransaction.php
12256 views
<?php12final class PhabricatorAuthFactorProviderDuoCredentialTransaction3extends PhabricatorAuthFactorProviderTransactionType {45const TRANSACTIONTYPE = 'duo.credential';67public function generateOldValue($object) {8$key = PhabricatorDuoAuthFactor::PROP_CREDENTIAL;9return $object->getAuthFactorProviderProperty($key);10}1112public function applyInternalEffects($object, $value) {13$key = PhabricatorDuoAuthFactor::PROP_CREDENTIAL;14$object->setAuthFactorProviderProperty($key, $value);15}1617public function getTitle() {18return pht(19'%s changed the credential for this provider from %s to %s.',20$this->renderAuthor(),21$this->renderOldHandle(),22$this->renderNewHandle());23}2425public function validateTransactions($object, array $xactions) {26$actor = $this->getActor();27$errors = array();2829if (!$this->isDuoProvider($object)) {30return $errors;31}3233$old_value = $this->generateOldValue($object);34if ($this->isEmptyTextTransaction($old_value, $xactions)) {35$errors[] = $this->newRequiredError(36pht('Duo providers must have an API credential.'));37}3839foreach ($xactions as $xaction) {40$new_value = $xaction->getNewValue();4142if (!strlen($new_value)) {43continue;44}4546if ($new_value === $old_value) {47continue;48}4950$credential = id(new PassphraseCredentialQuery())51->setViewer($actor)52->withIsDestroyed(false)53->withPHIDs(array($new_value))54->executeOne();55if (!$credential) {56$errors[] = $this->newInvalidError(57pht(58'Credential ("%s") is not valid.',59$new_value),60$xaction);61continue;62}63}6465return $errors;66}6768}697071