Skip to content

Commit

Permalink
Merge pull request #5 from burcev-alex/feat-custom-auth
Browse files Browse the repository at this point in the history
feat(config): Callback authorize
  • Loading branch information
bigperson authored Jul 21, 2022
2 parents 6603b59 + 4474cdc commit 34b7e71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Config
*/
private $filePart = 0;

/**
* @var null
*/
private $auth = [];

/**
* @var array
*/
Expand Down Expand Up @@ -135,6 +140,14 @@ public function getModelClass(string $modelName): ?string
return null;
}

/**
* @return null|array
*/
public function getAuth(): ?array
{
return $this->auth;
}

/**
* @param string $filename
*
Expand Down
18 changes: 14 additions & 4 deletions src/Services/AuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ public function checkAuth()
*/
public function auth(): void
{
$login = $this->config->getLogin();
$user = $this->session->get(self::SESSION_KEY.'_auth', null);
// пользовательская настройка авторизации
$configAuth = $this->config->getAuth();

if (!$user || $user != $login) {
throw new Exchange1CException('auth error');
if ($configAuth['custom']) {
$method = $configAuth['callback'];
if (!$method($this->config->getLogin(), $this->config->getPassword())) {
throw new Exchange1CException('auth error');
}
} else {
$login = $this->config->getLogin();
$user = $this->session->get(self::SESSION_KEY.'_auth', null);

if (!$user || $user != $login) {
throw new Exchange1CException('auth error');
}
}
}

Expand Down

0 comments on commit 34b7e71

Please sign in to comment.