validate when loging from database; phpCS

parent 02beb04b
......@@ -49,11 +49,18 @@ class RedBeanPHP extends AbstractAdapter
$events = $this->events;
$events('trigger', 'authenticate', $this);
$user = R::findOne('user', 'mail = ? AND authentication_source = ?', [
$this->getIdentity(),
'DB',
$email = filter_var($this->getIdentity(), FILTER_VALIDATE_EMAIL);
$isValidCredential = filter_var(strlen(trim($this->getCredential())), FILTER_VALIDATE_INT, [
'options'=> ['min_range' => 8],
]);
if (!$email || !$isValidCredential) {
return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, [self::$failMessage]);
}
$user = R::findOne('user', 'mail = ? AND authentication_source = ?', [$email, 'DB']);
if (!$user) {
return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, [self::$failMessage]);
}
......
......@@ -19,10 +19,10 @@ return function (Slim\App $app) {
return new SchMM\FetchUnit(new GuzzleHttp\Client([
'base_uri' => $settings['sch_mm']['api_url'],
'auth' => [
$settings['sch_mm']['api_user'],
'auth' => [
$settings['sch_mm']['api_user'],
$settings['sch_mm']['api_pass'],
],
]));
};
};
\ No newline at end of file
};
......@@ -31,16 +31,17 @@ class FetchUnit
public function __invoke($mmId)
{
$config = $this->httpClient->getConfig();
$baseUri = $config['base_uri'];
$auth = $config['auth'];
$url = $baseUri->withQueryValue($baseUri, 'registry_no', $mmId);
$config = $this->httpClient->getConfig();
$baseUri = $config['base_uri'];
$auth = $config['auth'];
$url = $baseUri->withQueryValue($baseUri, 'registry_no', $mmId);
$response = $this->httpClient->request('GET', $url, ['auth' => $auth]);
$responseData = json_decode($response->getBody()->getContents(), true);
if (!isset($responseData['data']) || empty($responseData['data'])) {
return null;
return;
}
return $responseData['data'][0];
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment