Source of file GetSsoLink.php
Size: 2,107 Bytes - Last Modified: 2021-12-24T07:10:29+00:00
/var/www/docs.ssmods.com/process/src/src/Api/Users/GetSsoLink.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php namespace Sunnysideup\Moodle\Api\Users; use SilverStripe\Security\Member; use Sunnysideup\Moodle\Api\MoodleAction; class GetSsoLink extends MoodleAction { protected $method = 'auth_userkey_request_login_url'; protected $resultGetArray = true; protected $resultTakeFirstEntry = false; protected $resultRelevantArrayKey = 'loginurl'; protected $resultVariableType = 'string'; protected $filterType = 'email'; protected const FILTER_TYPES_ALLOWED = ['email', 'idnumber',]; public function setFilterType(string $type) : self { if( in_array($type, self::FILTER_TYPES_ALLOWED)) { $this->filterType = $type; } else { user_error('Type must be one of: '.print_r(self::FILTER_TYPES_ALLOWED, 1).', "'.$type.'" provided.'); } return $this; } public function runAction($relevantData) { if ($this->validateParams($relevantData)) { $params = [ 'user' => $this->getFilterStatement($relevantData), ]; $result = $this->runActionInner($params); return $this->processResults($result); } return false; } protected function validateParams($relevantData): bool { if (! $relevantData instanceof Member) { $this->recordValidateParamsError('We need an ' . Member::class . ' to create this login. You provided: ' . print_r($relevantData, 1)); return false; } if ($relevantData->Email && filter_var($relevantData->Email, FILTER_VALIDATE_EMAIL)) { return true; } $this->recordValidateParamsError('We expect an email here, you provided ' . $relevantData->Email); return false; } protected function getFilterStatement($relevantData) : array { switch ($this->filterType) { case 'idnumber': return ['idnumber' => $relevantData->ID,]; break; case 'email': default: return ['email' => $relevantData->Email,]; } } } |