64 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace DataAccess\Security;
use BusinessLogic\Security\UserContextBuilder;
use DataAccess\CommonDao;
use Exception;
class UserGateway extends CommonDao {
/**
* @param $hashedToken string The pre-hashed token from Helpers::hashToken
* @param $heskSettings
* @return array|null User ResultSet if an active user for the token is found, null otherwise
*/
function getUserForAuthToken($hashedToken, $heskSettings) {
$this->init();
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` WHERE `id` = (
2017-01-30 22:10:14 -05:00
SELECT `user_id`
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "user_api_tokens`
2017-01-30 22:10:14 -05:00
WHERE `token` = '" . hesk_dbEscape($hashedToken) . "'
) AND `active` = '1'");
if (hesk_dbNumRows($rs) === 0) {
return null;
}
$row = hesk_dbFetchAssoc($rs);
$this->close();
return $row;
}
2017-02-26 21:52:12 -05:00
// TODO Replace this with a basic User retrieval
function getNameForId($id, $heskSettings) {
$this->init();
$rs = hesk_dbQuery("SELECT `name` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` WHERE `id` = " . intval($id));
if (hesk_dbNumRows($rs) === 0) {
return null;
}
$row = hesk_dbFetchAssoc($rs);
return $row['name'];
}
2017-03-06 21:44:38 -05:00
// TODO Replace this with a basic User retriever
function getEmailForId($id, $heskSettings) {
$this->init();
$rs = hesk_dbQuery("SELECT `email` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` WHERE `id` = " . intval($id));
if (hesk_dbNumRows($rs) === 0) {
return null;
}
$row = hesk_dbFetchAssoc($rs);
return $row['email'];
}
}