mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-20 13:28:42 +00:00
fixes #92
This commit is contained in:
parent
a929724ecf
commit
f4b5dd5f01
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user