Commit 7bb4c62f authored by Vassilis Kanellopoulos's avatar Vassilis Kanellopoulos
Browse files

validate when loging from database; phpCS

parent 02beb04b
...@@ -49,11 +49,18 @@ class RedBeanPHP extends AbstractAdapter ...@@ -49,11 +49,18 @@ class RedBeanPHP extends AbstractAdapter
$events = $this->events; $events = $this->events;
$events('trigger', 'authenticate', $this); $events('trigger', 'authenticate', $this);
$user = R::findOne('user', 'mail = ? AND authentication_source = ?', [
$this->getIdentity(), $email = filter_var($this->getIdentity(), FILTER_VALIDATE_EMAIL);
'DB', $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) { if (!$user) {
return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, [self::$failMessage]); return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, [self::$failMessage]);
} }
......
...@@ -19,10 +19,10 @@ return function (Slim\App $app) { ...@@ -19,10 +19,10 @@ return function (Slim\App $app) {
return new SchMM\FetchUnit(new GuzzleHttp\Client([ return new SchMM\FetchUnit(new GuzzleHttp\Client([
'base_uri' => $settings['sch_mm']['api_url'], 'base_uri' => $settings['sch_mm']['api_url'],
'auth' => [ 'auth' => [
$settings['sch_mm']['api_user'], $settings['sch_mm']['api_user'],
$settings['sch_mm']['api_pass'], $settings['sch_mm']['api_pass'],
], ],
])); ]));
}; };
}; };
\ No newline at end of file
...@@ -31,16 +31,17 @@ class FetchUnit ...@@ -31,16 +31,17 @@ class FetchUnit
public function __invoke($mmId) public function __invoke($mmId)
{ {
$config = $this->httpClient->getConfig(); $config = $this->httpClient->getConfig();
$baseUri = $config['base_uri']; $baseUri = $config['base_uri'];
$auth = $config['auth']; $auth = $config['auth'];
$url = $baseUri->withQueryValue($baseUri, 'registry_no', $mmId); $url = $baseUri->withQueryValue($baseUri, 'registry_no', $mmId);
$response = $this->httpClient->request('GET', $url, ['auth' => $auth]); $response = $this->httpClient->request('GET', $url, ['auth' => $auth]);
$responseData = json_decode($response->getBody()->getContents(), true); $responseData = json_decode($response->getBody()->getContents(), true);
if (!isset($responseData['data']) || empty($responseData['data'])) { if (!isset($responseData['data']) || empty($responseData['data'])) {
return null; return;
} }
return $responseData['data'][0]; 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