]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Remove deprecated App::getBaseURL() - process methods to DI::baseUrl()->get()
[friendica.git] / src / Model / User.php
index b6121ad04e07c46098f2eeec60b8cf8e17dbf07f..22a8b04744c87a17d1e8589ac1898b2cf94cceec 100644 (file)
@@ -18,11 +18,12 @@ use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Model\Photo;
+use Friendica\DI;
 use Friendica\Model\TwoFactor\AppSpecificPassword;
 use Friendica\Object\Image;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Worker\Delivery;
@@ -105,6 +106,27 @@ class User
                return DBA::selectFirst('user', $fields, ['uid' => $uid]);
        }
 
+       /**
+        * Returns a user record based on it's GUID
+        *
+        * @param string $guid   The guid of the user
+        * @param array  $fields The fields to retrieve
+        * @param bool   $active True, if only active records are searched
+        *
+        * @return array|boolean User record if it exists, false otherwise
+        * @throws Exception
+        */
+       public static function getByGuid(string $guid, array $fields = [], bool $active = true)
+       {
+               if ($active) {
+                       $cond = ['guid' => $guid, 'account_expired' => false, 'account_removed' => false];
+               } else {
+                       $cond = ['guid' => $guid];
+               }
+
+               return DBA::selectFirst('user', $fields, $cond);
+       }
+
        /**
         * @param  string        $nickname
         * @param array          $fields
@@ -170,7 +192,8 @@ class User
                        `user`.`page-flags`,
                        `user`.`account-type`,
                        `user`.`prvnets`,
-                       `user`.`account_removed`
+                       `user`.`account_removed`,
+                       `user`.`hidewall`
                        FROM `contact`
                        INNER JOIN `user`
                                ON `user`.`uid` = `contact`.`uid`
@@ -412,6 +435,7 @@ class User
         *
         * @param string $password
         * @return bool
+        * @throws Exception
         */
        public static function isPasswordExposed($password)
        {
@@ -420,9 +444,20 @@ class User
                        'cacheDirectory' => get_temppath() . '/password-exposed-cache/',
                ]);
 
-               $PasswordExposedCHecker = new PasswordExposed\PasswordExposedChecker(null, $cache);
+               try {
+                       $passwordExposedChecker = new PasswordExposed\PasswordExposedChecker(null, $cache);
 
-               return $PasswordExposedCHecker->passwordExposed($password) === PasswordExposed\PasswordStatus::EXPOSED;
+                       return $passwordExposedChecker->passwordExposed($password) === PasswordExposed\PasswordStatus::EXPOSED;
+               } catch (\Exception $e) {
+                       Logger::error('Password Exposed Exception: ' . $e->getMessage(), [
+                               'code' => $e->getCode(),
+                               'file' => $e->getFile(),
+                               'line' => $e->getLine(),
+                               'trace' => $e->getTraceAsString()
+                       ]);
+
+                       return false;
+               }
        }
 
        /**
@@ -553,7 +588,6 @@ class User
         */
        public static function create(array $data)
        {
-               $a = \get_app();
                $return = ['user' => null, 'password' => ''];
 
                $using_invites = Config::get('system', 'invitation_only');
@@ -590,6 +624,7 @@ class User
                        }
                }
 
+               /// @todo Check if this part is really needed. We should have fetched all this data in advance
                if (empty($username) || empty($email) || empty($nickname)) {
                        if ($openid_url) {
                                if (!Network::isUrlValid($openid_url)) {
@@ -598,7 +633,7 @@ class User
                                $_SESSION['register'] = 1;
                                $_SESSION['openid'] = $openid_url;
 
-                               $openid = new LightOpenID($a->getHostName());
+                               $openid = new LightOpenID(DI::baseUrl()->getHostname());
                                $openid->identity = $openid_url;
                                $openid->returnUrl = System::baseUrl() . '/openid';
                                $openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
@@ -795,15 +830,15 @@ class User
                        $filename = basename($photo);
                        $img_str = Network::fetchUrl($photo, true);
                        // guess mimetype from headers or filename
-                       $type = Image::guessType($photo, true);
+                       $type = Images::guessType($photo, true);
 
                        $Image = new Image($img_str, $type);
                        if ($Image->isValid()) {
                                $Image->scaleToSquare(300);
 
-                               $hash = Photo::newResource();
+                               $resource_id = Photo::newResource();
 
-                               $r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 4);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 4);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -811,7 +846,7 @@ class User
 
                                $Image->scaleDown(80);
 
-                               $r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 5);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 5);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -819,14 +854,14 @@ class User
 
                                $Image->scaleDown(48);
 
-                               $r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 6);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 6);
 
                                if ($r === false) {
                                        $photo_failure = true;
                                }
 
                                if (!$photo_failure) {
-                                       Photo::update(['profile' => 1], ['resource-id' => $hash]);
+                                       Photo::update(['profile' => 1], ['resource-id' => $resource_id]);
                                }
                        }
                }
@@ -881,6 +916,7 @@ class User
         *
         * It's here as a function because the mail is sent from different parts
         *
+        * @param L10n\L10n   $l10n     The used language
         * @param array  $user     User record array
         * @param string $sitename
         * @param string $siteurl
@@ -888,9 +924,9 @@ class User
         * @return NULL|boolean from notification() and email() inherited
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function sendRegisterOpenEmail($user, $sitename, $siteurl, $password)
+       public static function sendRegisterOpenEmail(L10n\L10n $l10n, $user, $sitename, $siteurl, $password)
        {
-               $preamble = Strings::deindent(L10n::t(
+               $preamble = Strings::deindent($l10n->t(
                        '
                                Dear %1$s,
                                Thank you for registering at %2$s. Your account has been created.
@@ -898,7 +934,7 @@ class User
                        $user['username'],
                        $sitename
                ));
-               $body = Strings::deindent(L10n::t(
+               $body = Strings::deindent($l10n->t(
                        '
                        The login details are as follows: