This commit is contained in:
Dennis Eichhorn 2017-03-31 15:49:28 +02:00
parent a929724ecf
commit f4b5dd5f01
2 changed files with 0 additions and 84 deletions

View File

@ -108,29 +108,6 @@ class AccountManager implements \Countable
return $this->accounts[$id] ?? new NullAccount();
}
/**
* Login user.
*
* @param int $account Account id
* @param string $login Username
* @param string $password Password
*
* @return int
*
* @throws \Exception Throws this exception if the account to login is not found in the AccountManager.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function login(int $account, string $login, string $password) : int
{
if (!isset($this->accounts[$account])) {
throw new \Exception('Account not found in the account manager.');
}
return $this->auth->login($login, $password);
}
/**
* Add account.
*

View File

@ -86,67 +86,6 @@ class Auth
return $uid;
}
/**
* Login user.
*
* @param string $login Username
* @param string $password Password
*
* @return int Login code
*
* @todo move this to the admin accountMapper
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function login(string $login, string $password) : int
{
try {
$result = null;
switch ($this->connection->getType()) {
case DatabaseType::MYSQL:
$sth = $this->connection->con->prepare(
'SELECT
`' . $this->connection->prefix . 'account`.*
FROM
`' . $this->connection->prefix . 'account`
WHERE
`account_login` = :login'
);
$sth->bindValue(':login', $login, \PDO::PARAM_STR);
$sth->execute();
$result = $sth->fetchAll();
break;
}
// TODO: check if user is allowed to login on THIS page (backend|frontend|etc...)
if (!isset($result[0])) {
return LoginReturnType::WRONG_USERNAME;
}
$result = $result[0];
if ($result['account_tries'] <= 0) {
return LoginReturnType::WRONG_INPUT_EXCEEDED;
}
if (password_verify($password, $result['account_password'])) {
$this->session->set('UID', $result['account_id']);
$this->session->save();
return LoginReturnType::OK;
}
return LoginReturnType::WRONG_PASSWORD;
} catch (\Exception $e) {
return LoginReturnType::FAILURE;
}
}
/**
* Logout the given user.
*