]> git.mxchange.org Git - friendica.git/commitdiff
Remove unused upubkey and uprvkey from queries
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 26 Nov 2017 19:55:47 +0000 (14:55 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Sun, 26 Nov 2017 19:55:47 +0000 (14:55 -0500)
- Switched queries to new dba::* functions

include/auth.php
include/security.php
mod/openid.php
mod/settings.php
src/Model/User.php
src/Worker/Delivery.php
src/Worker/Notifier.php
src/Worker/Queue.php

index 181ba71a629699fad700c417b9a6a2de74f1cbb5..5da71ef6e1a10823a222bb51ded54e8a74794053 100644 (file)
@@ -13,13 +13,21 @@ require_once 'include/datetime.php';
 if (isset($_COOKIE["Friendica"])) {
        $data = json_decode($_COOKIE["Friendica"]);
        if (isset($data->uid)) {
-               $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
-               FROM `user` WHERE `uid` = %d AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1",
-                       intval($data->uid)
+
+               $user = dba::select('user',
+                       [],
+                       [
+                               'uid' => intval($data->uid),
+                               'blocked' => 0,
+                               'account_expired' => 0,
+                               'account_removed' => 0,
+                               'verified' => 1,
+                       ],
+                       ['limit' => 1]
                );
 
-               if ($r) {
-                       if ($data->hash != cookie_hash($r[0])) {
+               if (DBM::is_result($user)) {
+                       if ($data->hash != cookie_hash($user)) {
                                logger("Hash for user " . $data->uid . " doesn't fit.");
                                nuke_session();
                                goaway(System::baseUrl());
@@ -29,11 +37,11 @@ if (isset($_COOKIE["Friendica"])) {
                        // Expires after 7 days by default,
                        // can be set via system.auth_cookie_lifetime
                        $authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);
-                       new_cookie($authcookiedays * 24 * 60 * 60, $r[0]);
+                       new_cookie($authcookiedays * 24 * 60 * 60, $user);
 
                        // Do the authentification if not done by now
                        if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
-                               authenticate_success($r[0]);
+                               authenticate_success($user);
 
                                if (Config::get('system', 'paranoia')) {
                                        $_SESSION['addr'] = $data->ip;
@@ -75,12 +83,18 @@ if (isset($_SESSION) && x($_SESSION, 'authenticated') && (!x($_POST, 'auth-param
                        goaway(System::baseUrl());
                }
 
-               $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
-               FROM `user` WHERE `uid` = %d AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1",
-                       intval($_SESSION['uid'])
+               $user = dba::select('user',
+                       [],
+                       [
+                               'uid' => intval($_SESSION['uid']),
+                               'blocked' => 0,
+                               'account_expired' => 0,
+                               'account_removed' => 0,
+                               'verified' => 1,
+                       ],
+                       ['limit' => 1]
                );
-
-               if (!DBM::is_result($r)) {
+               if (!DBM::is_result($user)) {
                        nuke_session();
                        goaway(System::baseUrl());
                }
@@ -95,7 +109,7 @@ if (isset($_SESSION) && x($_SESSION, 'authenticated') && (!x($_POST, 'auth-param
                        $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');
                        $login_refresh = true;
                }
-               authenticate_success($r[0], false, false, $login_refresh);
+               authenticate_success($user, false, false, $login_refresh);
        }
 } else {
        session_unset();
index 18793ce0602bd949e568a69886190df954071340..6f6ef94b6937cba12c154fa37dfc1e0dce6427c3 100644 (file)
@@ -15,7 +15,7 @@ use Friendica\Database\DBM;
  */
 function cookie_hash($user) {
        return(hash("sha256", Config::get("system", "site_prvkey").
-                               $user["uprvkey"].
+                               $user["prvkey"].
                                $user["password"]));
 }
 
index 45b80638d5e3723ea306c8ed09cf1df112a85dd6..613cd222f605e962301492f73f4a8d033fb9c7a7 100644 (file)
@@ -33,7 +33,8 @@ function openid_content(App $a) {
                        //       mod/settings.php in 8367cad so it might have left mixed
                        //       records in the user table
                        //
-                       $r = q("SELECT *, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` FROM `user`
+                       $r = q("SELECT *
+                               FROM `user`
                                WHERE ( `openid` = '%s' OR `openid` = '%s' )
                                AND `blocked` = 0 AND `account_expired` = 0
                                AND `account_removed` = 0 AND `verified` = 1
index 7628f77825effa074f9502372258cb6e8e698fae..8ad82b023d67501f973e4b28a4fc554ac6651e8c 100644 (file)
@@ -506,14 +506,14 @@ function settings_post(App $a) {
                }
                //  check the email is valid
                if (!valid_email($email)) {
-                       $err .= t(' Not valid email.');
+                       $err .= t('Invalid email.');
                }
                //  ensure new email is not the admin mail
                //if ((x($a->config, 'admin_email')) && (strcasecmp($email, $a->config['admin_email']) == 0)) {
                if (x($a->config, 'admin_email')) {
                        $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email'])));
                        if (in_array(strtolower($email), $adminlist)) {
-                               $err .= t(' Cannot change to that email.');
+                               $err .= t('Cannot change to that email.');
                                $email = $a->user['email'];
                        }
                }
index a7f59b6a3d0a2bd4bc5aec32a6343c39c0ce4b1e..87663dbe5f22501930299d262826c9a1f02299a4 100644 (file)
@@ -78,21 +78,20 @@ class User
 
                logger('Removing user: ' . $uid);
 
-               $r = dba::select('user', array(), array('uid' => $uid), array("limit" => 1));
+               $user = dba::select('user', [], ['uid' => $uid], ['limit' => 1]);
 
-               call_hooks('remove_user', $r);
+               call_hooks('remove_user', $user);
 
                // save username (actually the nickname as it is guaranteed
                // unique), so it cannot be re-registered in the future.
-
-               dba::insert('userd', array('username' => $r['nickname']));
+               dba::insert('userd', ['username' => $user['nickname']]);
 
                // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
-               q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
+               dba::update('user', ['account_removed' => 1, 'account_expires_on' => datetime_convert()], ['uid' => intval($uid)]);
                Worker::add(PRIORITY_HIGH, "Notifier", "removeme", $uid);
 
                // Send an update to the directory
-               Worker::add(PRIORITY_LOW, "Directory", $r['url']);
+               Worker::add(PRIORITY_LOW, "Directory", $user['url']);
 
                if ($uid == local_user()) {
                        unset($_SESSION['authenticated']);
index 216d2520d95a97e37eb505272bd5391050607440..c47e98287b7adeb352afe182d11917430265745c 100644 (file)
@@ -140,7 +140,7 @@ class Delivery {
                        }
                }
 
-               $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
+               $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`,
                        `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
                        `user`.`page-flags`, `user`.`account-type`, `user`.`prvnets`
                        FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
index ac8cf123c5a8d4e6a02109877b80a12b7bcf682e..b261b32fc0444b2ecf657026bbbfe2756cbe506f 100644 (file)
@@ -108,7 +108,7 @@ class Notifier {
                        $recipients[] = $suggest[0]['cid'];
                        $item = $suggest[0];
                } elseif ($cmd === 'removeme') {
-                       $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
+                       $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`,
                                        `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
                                        `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid`
                                FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
@@ -173,7 +173,7 @@ class Notifier {
 
                }
 
-               $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
+               $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`,
                        `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
                        `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`
                        FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
index 73726098e993b861c98a89462050801fe41d2a86..f09def003d5d9423c18ebe5a9f614e430ce69298 100644 (file)
@@ -80,33 +80,29 @@ class Queue
 
                $q_item = $r[0];
 
-               $c = q(
-                       "SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
-                       intval($q_item['cid'])
-               );
-
-               if (!DBM::is_result($c)) {
+               $contact = dba::select('contact', [], ['id' => intval($q_item['cid'])], ['limit' => 1]);
+               if (!DBM::is_result($contact)) {
                        remove_queue_item($q_item['id']);
                        return;
                }
 
-               $dead = Cache::get($cachekey_deadguy . $c[0]['notify']);
+               $dead = Cache::get($cachekey_deadguy . $contact['notify']);
 
                if (!is_null($dead) && $dead) {
-                       logger('queue: skipping known dead url: ' . $c[0]['notify']);
+                       logger('queue: skipping known dead url: ' . $contact['notify']);
                        update_queue_time($q_item['id']);
                        return;
                }
 
-               $server = PortableContact::detectServer($c[0]['url']);
+               $server = PortableContact::detectServer($contact['url']);
 
                if ($server != "") {
                        $vital = Cache::get($cachekey_server . $server);
 
                        if (is_null($vital)) {
-                               logger("Check server " . $server . " (" . $c[0]["network"] . ")");
+                               logger("Check server " . $server . " (" . $contact["network"] . ")");
 
-                               $vital = PortableContact::checkServer($server, $c[0]["network"], true);
+                               $vital = PortableContact::checkServer($server, $contact["network"], true);
                                Cache::set($cachekey_server . $server, $vital, CACHE_QUARTER_HOUR);
                        }
 
@@ -117,12 +113,8 @@ class Queue
                        }
                }
 
-               $u = q(
-                       "SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
-                       FROM `user` WHERE `uid` = %d LIMIT 1",
-                       intval($c[0]['uid'])
-               );
-               if (!DBM::is_result($u)) {
+               $user = dba::select('user', [], ['uid' => intval($contact['uid'])], ['limit' => 1]);
+               if (!DBM::is_result($user)) {
                        remove_queue_item($q_item['id']);
                        return;
                }