1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-03 14:47:30 +02:00

Make use of database name, schema or other qualifier in all statements

This commit is contained in:
Marco
2018-08-28 23:44:50 +02:00
parent f70923679f
commit 382832457d
3 changed files with 36 additions and 36 deletions

View File

@@ -278,7 +278,7 @@ final class Administration extends UserManager {
$userId = (int) $userId; $userId = (int) $userId;
$rolesBitmask = $this->db->selectValue( $rolesBitmask = $this->db->selectValue(
'SELECT roles_mask FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT roles_mask FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $userId ] [ $userId ]
); );
@@ -304,7 +304,7 @@ final class Administration extends UserManager {
$userId = (int) $userId; $userId = (int) $userId;
$rolesBitmask = $this->db->selectValue( $rolesBitmask = $this->db->selectValue(
'SELECT roles_mask FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT roles_mask FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $userId ] [ $userId ]
); );
@@ -431,7 +431,7 @@ final class Administration extends UserManager {
private function deleteUsersByColumnValue($columnName, $columnValue) { private function deleteUsersByColumnValue($columnName, $columnValue) {
try { try {
return $this->db->delete( return $this->db->delete(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ [
$columnName => $columnValue $columnName => $columnValue
] ]
@@ -458,7 +458,7 @@ final class Administration extends UserManager {
private function modifyRolesForUserByColumnValue($columnName, $columnValue, callable $modification) { private function modifyRolesForUserByColumnValue($columnName, $columnValue, callable $modification) {
try { try {
$userData = $this->db->selectRow( $userData = $this->db->selectRow(
'SELECT id, roles_mask FROM ' . $this->dbTablePrefix . 'users WHERE ' . $columnName . ' = ?', 'SELECT id, roles_mask FROM ' . $this->makeTableName('users') . ' WHERE ' . $columnName . ' = ?',
[ $columnValue ] [ $columnValue ]
); );
} }
@@ -474,7 +474,7 @@ final class Administration extends UserManager {
try { try {
$this->db->exec( $this->db->exec(
'UPDATE ' . $this->dbTablePrefix . 'users SET roles_mask = ? WHERE id = ?', 'UPDATE ' . $this->makeTableName('users') . ' SET roles_mask = ? WHERE id = ?',
[ [
$newRolesBitmask, $newRolesBitmask,
(int) $userData['id'] (int) $userData['id']
@@ -550,7 +550,7 @@ final class Administration extends UserManager {
private function logInAsUserByColumnValue($columnName, $columnValue) { private function logInAsUserByColumnValue($columnName, $columnValue) {
try { try {
$users = $this->db->select( $users = $this->db->select(
'SELECT verified, id, email, username, status, roles_mask FROM ' . $this->dbTablePrefix . 'users WHERE ' . $columnName . ' = ? LIMIT 2 OFFSET 0', 'SELECT verified, id, email, username, status, roles_mask FROM ' . $this->makeTableName('users') . ' WHERE ' . $columnName . ' = ? LIMIT 2 OFFSET 0',
[ $columnValue ] [ $columnValue ]
); );
} }

View File

@@ -115,7 +115,7 @@ final class Auth extends UserManager {
if (!empty($parts[0]) && !empty($parts[1])) { if (!empty($parts[0]) && !empty($parts[1])) {
try { try {
$rememberData = $this->db->selectRow( $rememberData = $this->db->selectRow(
'SELECT a.user, a.token, a.expires, b.email, b.username, b.status, b.roles_mask, b.force_logout FROM ' . $this->dbTablePrefix . 'users_remembered AS a JOIN ' . $this->dbTablePrefix . 'users AS b ON a.user = b.id WHERE a.selector = ?', 'SELECT a.user, a.token, a.expires, b.email, b.username, b.status, b.roles_mask, b.force_logout FROM ' . $this->makeTableName('users_remembered') . ' AS a JOIN ' . $this->makeTableName('users') . ' AS b ON a.user = b.id WHERE a.selector = ?',
[ $parts[0] ] [ $parts[0] ]
); );
} }
@@ -157,7 +157,7 @@ final class Auth extends UserManager {
// fetch the authoritative data from the database again // fetch the authoritative data from the database again
try { try {
$authoritativeData = $this->db->selectRow( $authoritativeData = $this->db->selectRow(
'SELECT email, username, status, roles_mask, force_logout FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT email, username, status, roles_mask, force_logout FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $this->getUserId() ] [ $this->getUserId() ]
); );
} }
@@ -354,7 +354,7 @@ final class Auth extends UserManager {
try { try {
$expectedHash = $this->db->selectValue( $expectedHash = $this->db->selectValue(
'SELECT password FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT password FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $this->getUserId() ] [ $this->getUserId() ]
); );
} }
@@ -497,7 +497,7 @@ final class Auth extends UserManager {
try { try {
$this->db->insert( $this->db->insert(
$this->dbTablePrefix . 'users_remembered', $this->makeTableNameComponents('users_remembered'),
[ [
'user' => $userId, 'user' => $userId,
'selector' => $selector, 'selector' => $selector,
@@ -567,7 +567,7 @@ final class Auth extends UserManager {
// update the timestamp of the user's last login // update the timestamp of the user's last login
try { try {
$this->db->update( $this->db->update(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ 'last_login' => \time() ], [ 'last_login' => \time() ],
[ 'id' => $userId ] [ 'id' => $userId ]
); );
@@ -621,7 +621,7 @@ final class Auth extends UserManager {
try { try {
$confirmationData = $this->db->selectRow( $confirmationData = $this->db->selectRow(
'SELECT a.id, a.user_id, a.email AS new_email, a.token, a.expires, b.email AS old_email FROM ' . $this->dbTablePrefix . 'users_confirmations AS a JOIN ' . $this->dbTablePrefix . 'users AS b ON b.id = a.user_id WHERE a.selector = ?', 'SELECT a.id, a.user_id, a.email AS new_email, a.token, a.expires, b.email AS old_email FROM ' . $this->makeTableName('users_confirmations') . ' AS a JOIN ' . $this->makeTableName('users') . ' AS b ON b.id = a.user_id WHERE a.selector = ?',
[ $selector ] [ $selector ]
); );
} }
@@ -635,7 +635,7 @@ final class Auth extends UserManager {
// invalidate any potential outstanding password reset requests // invalidate any potential outstanding password reset requests
try { try {
$this->db->delete( $this->db->delete(
$this->dbTablePrefix . 'users_resets', $this->makeTableNameComponents('users_resets'),
[ 'user' => $confirmationData['user_id'] ] [ 'user' => $confirmationData['user_id'] ]
); );
} }
@@ -646,7 +646,7 @@ final class Auth extends UserManager {
// mark the email address as verified (and possibly update it to the new address given) // mark the email address as verified (and possibly update it to the new address given)
try { try {
$this->db->update( $this->db->update(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ [
'email' => $confirmationData['new_email'], 'email' => $confirmationData['new_email'],
'verified' => 1 'verified' => 1
@@ -673,7 +673,7 @@ final class Auth extends UserManager {
// consume the token just being used for confirmation // consume the token just being used for confirmation
try { try {
$this->db->delete( $this->db->delete(
$this->dbTablePrefix . 'users_confirmations', $this->makeTableNameComponents('users_confirmations'),
[ 'id' => $confirmationData['id'] ] [ 'id' => $confirmationData['id'] ]
); );
} }
@@ -818,7 +818,7 @@ final class Auth extends UserManager {
try { try {
$existingUsersWithNewEmail = $this->db->selectValue( $existingUsersWithNewEmail = $this->db->selectValue(
'SELECT COUNT(*) FROM ' . $this->dbTablePrefix . 'users WHERE email = ?', 'SELECT COUNT(*) FROM ' . $this->makeTableName('users') . ' WHERE email = ?',
[ $newEmail ] [ $newEmail ]
); );
} }
@@ -832,7 +832,7 @@ final class Auth extends UserManager {
try { try {
$verified = $this->db->selectValue( $verified = $this->db->selectValue(
'SELECT verified FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT verified FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $this->getUserId() ] [ $this->getUserId() ]
); );
} }
@@ -920,7 +920,7 @@ final class Auth extends UserManager {
private function resendConfirmationForColumnValue($columnName, $columnValue, callable $callback) { private function resendConfirmationForColumnValue($columnName, $columnValue, callable $callback) {
try { try {
$latestAttempt = $this->db->selectRow( $latestAttempt = $this->db->selectRow(
'SELECT user_id, email FROM ' . $this->dbTablePrefix . 'users_confirmations WHERE ' . $columnName . ' = ? ORDER BY id DESC LIMIT 1 OFFSET 0', 'SELECT user_id, email FROM ' . $this->makeTableName('users_confirmations') . ' WHERE ' . $columnName . ' = ? ORDER BY id DESC LIMIT 1 OFFSET 0',
[ $columnValue ] [ $columnValue ]
); );
} }
@@ -1133,7 +1133,7 @@ final class Auth extends UserManager {
try { try {
$projection = \implode(', ', $requestedColumns); $projection = \implode(', ', $requestedColumns);
$userData = $this->db->selectRow( $userData = $this->db->selectRow(
'SELECT ' . $projection . ' FROM ' . $this->dbTablePrefix . 'users WHERE email = ?', 'SELECT ' . $projection . ' FROM ' . $this->makeTableName('users') . ' WHERE email = ?',
[ $email ] [ $email ]
); );
} }
@@ -1159,7 +1159,7 @@ final class Auth extends UserManager {
private function getOpenPasswordResetRequests($userId) { private function getOpenPasswordResetRequests($userId) {
try { try {
$requests = $this->db->selectValue( $requests = $this->db->selectValue(
'SELECT COUNT(*) FROM ' . $this->dbTablePrefix . 'users_resets WHERE user = ? AND expires > ?', 'SELECT COUNT(*) FROM ' . $this->makeTableName('users_resets') . ' WHERE user = ? AND expires > ?',
[ [
$userId, $userId,
\time() \time()
@@ -1202,7 +1202,7 @@ final class Auth extends UserManager {
try { try {
$this->db->insert( $this->db->insert(
$this->dbTablePrefix . 'users_resets', $this->makeTableNameComponents('users_resets'),
[ [
'user' => $userId, 'user' => $userId,
'selector' => $selector, 'selector' => $selector,
@@ -1245,7 +1245,7 @@ final class Auth extends UserManager {
try { try {
$resetData = $this->db->selectRow( $resetData = $this->db->selectRow(
'SELECT a.id, a.user, a.token, a.expires, b.resettable FROM ' . $this->dbTablePrefix . 'users_resets AS a JOIN ' . $this->dbTablePrefix . 'users AS b ON b.id = a.user WHERE a.selector = ?', 'SELECT a.id, a.user, a.token, a.expires, b.resettable FROM ' . $this->makeTableName('users_resets') . ' AS a JOIN ' . $this->makeTableName('users') . ' AS b ON b.id = a.user WHERE a.selector = ?',
[ $selector ] [ $selector ]
); );
} }
@@ -1263,7 +1263,7 @@ final class Auth extends UserManager {
try { try {
$this->db->delete( $this->db->delete(
$this->dbTablePrefix . 'users_resets', $this->makeTableNameComponents('users_resets'),
[ 'id' => $resetData['id'] ] [ 'id' => $resetData['id'] ]
); );
} }
@@ -1356,7 +1356,7 @@ final class Auth extends UserManager {
if ($this->isLoggedIn()) { if ($this->isLoggedIn()) {
try { try {
$this->db->update( $this->db->update(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ [
'resettable' => $enabled ? 1 : 0 'resettable' => $enabled ? 1 : 0
], ],
@@ -1385,7 +1385,7 @@ final class Auth extends UserManager {
if ($this->isLoggedIn()) { if ($this->isLoggedIn()) {
try { try {
$enabled = $this->db->selectValue( $enabled = $this->db->selectValue(
'SELECT resettable FROM ' . $this->dbTablePrefix . 'users WHERE id = ?', 'SELECT resettable FROM ' . $this->makeTableName('users') . ' WHERE id = ?',
[ $this->getUserId() ] [ $this->getUserId() ]
); );
@@ -1692,7 +1692,7 @@ final class Auth extends UserManager {
try { try {
$bucket = $this->db->selectRow( $bucket = $this->db->selectRow(
'SELECT tokens, replenished_at FROM ' . $this->dbTablePrefix . 'users_throttling WHERE bucket = ?', 'SELECT tokens, replenished_at FROM ' . $this->makeTableName('users_throttling') . ' WHERE bucket = ?',
[ $key ] [ $key ]
); );
} }
@@ -1729,7 +1729,7 @@ final class Auth extends UserManager {
// merge the updated bucket into the database // merge the updated bucket into the database
try { try {
$affected = $this->db->update( $affected = $this->db->update(
$this->dbTablePrefix . 'users_throttling', $this->makeTableNameComponents('users_throttling'),
$bucket, $bucket,
[ 'bucket' => $key ] [ 'bucket' => $key ]
); );
@@ -1743,7 +1743,7 @@ final class Auth extends UserManager {
try { try {
$this->db->insert( $this->db->insert(
$this->dbTablePrefix . 'users_throttling', $this->makeTableNameComponents('users_throttling'),
$bucket $bucket
); );
} }
@@ -1869,7 +1869,7 @@ final class Auth extends UserManager {
if (isset($existingSelector)) { if (isset($existingSelector)) {
// fetch the expiry date for the given selector // fetch the expiry date for the given selector
$existingExpiry = $this->db->selectValue( $existingExpiry = $this->db->selectValue(
'SELECT expires FROM ' . $this->dbTablePrefix . 'users_remembered WHERE selector = ? AND user = ?', 'SELECT expires FROM ' . $this->makeTableName('users_remembered') . ' WHERE selector = ? AND user = ?',
[ [
$existingSelector, $existingSelector,
$this->getUserId() $this->getUserId()

View File

@@ -144,7 +144,7 @@ abstract class UserManager {
if ($username !== null) { if ($username !== null) {
// count the number of users who do already have that specified username // count the number of users who do already have that specified username
$occurrencesOfUsername = $this->db->selectValue( $occurrencesOfUsername = $this->db->selectValue(
'SELECT COUNT(*) FROM ' . $this->dbTablePrefix . 'users WHERE username = ?', 'SELECT COUNT(*) FROM ' . $this->makeTableName('users') . ' WHERE username = ?',
[ $username ] [ $username ]
); );
@@ -161,7 +161,7 @@ abstract class UserManager {
try { try {
$this->db->insert( $this->db->insert(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ [
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
@@ -201,7 +201,7 @@ abstract class UserManager {
try { try {
$affected = $this->db->update( $affected = $this->db->update(
$this->dbTablePrefix . 'users', $this->makeTableNameComponents('users'),
[ 'password' => $newPassword ], [ 'password' => $newPassword ],
[ 'id' => $userId ] [ 'id' => $userId ]
); );
@@ -262,7 +262,7 @@ abstract class UserManager {
$projection = \implode(', ', $requestedColumns); $projection = \implode(', ', $requestedColumns);
$users = $this->db->select( $users = $this->db->select(
'SELECT ' . $projection . ' FROM ' . $this->dbTablePrefix . 'users WHERE username = ? LIMIT 2 OFFSET 0', 'SELECT ' . $projection . ' FROM ' . $this->makeTableName('users') . ' WHERE username = ? LIMIT 2 OFFSET 0',
[ $username ] [ $username ]
); );
} }
@@ -349,7 +349,7 @@ abstract class UserManager {
try { try {
$this->db->insert( $this->db->insert(
$this->dbTablePrefix . 'users_confirmations', $this->makeTableNameComponents('users_confirmations'),
[ [
'user_id' => (int) $userId, 'user_id' => (int) $userId,
'email' => $email, 'email' => $email,
@@ -389,7 +389,7 @@ abstract class UserManager {
try { try {
$this->db->delete( $this->db->delete(
$this->dbTablePrefix . 'users_remembered', $this->makeTableNameComponents('users_remembered'),
$whereMappings $whereMappings
); );
} }
@@ -407,7 +407,7 @@ abstract class UserManager {
protected function forceLogoutForUserById($userId) { protected function forceLogoutForUserById($userId) {
$this->deleteRememberDirectiveForUserById($userId); $this->deleteRememberDirectiveForUserById($userId);
$this->db->exec( $this->db->exec(
'UPDATE ' . $this->dbTablePrefix . 'users SET force_logout = force_logout + 1 WHERE id = ?', 'UPDATE ' . $this->makeTableName('users') . ' SET force_logout = force_logout + 1 WHERE id = ?',
[ $userId ] [ $userId ]
); );
} }