Bläddra i källkod

Update findEmail() method for ProviderUser

Visman 2 år sedan
förälder
incheckning
934f7a1da0
2 ändrade filer med 8 tillägg och 9 borttagningar
  1. 2 2
      app/Models/Pages/RegLog.php
  2. 6 7
      app/Models/ProviderUser/ProviderUser.php

+ 2 - 2
app/Models/Pages/RegLog.php

@@ -88,7 +88,7 @@ class RegLog extends Page
             if (empty($uid)) {
                 // на форуме есть пользователь с таким email
                 if (
-                    $this->c->providerUser->findEmail($provider) > 0
+                    $this->c->providerUser->findByEmail($provider->userEmail) > 0
                     || $this->c->users->loadByEmail($provider->userEmail) instanceof User
                 ) {
                     $auth         = $this->c->Auth;
@@ -182,7 +182,7 @@ class RegLog extends Page
                 return $redirect->message('Already linked to another', FORK_MESS_WARN, 5);
             }
 
-            $uid = $this->c->providerUser->findEmail($provider);
+            $uid = $this->c->providerUser->findByEmail($provider->userEmail);
 
             // email принадлежит другому пользователю
             if (

+ 6 - 7
app/Models/ProviderUser/ProviderUser.php

@@ -53,17 +53,16 @@ class ProviderUser extends Model
     }
 
     /**
-     * Возращает id локального пользователя по данным провайдера или 0
-     * Поиск идет по email
+     * Возращает id локального пользователя по email или 0
      */
-    public function findEmail(Driver $provider): int
+    public function findByEmail(string $email): int
     {
-        if ('' == $provider->userEmail) {
-            throw new RuntimeException('The user email is empty');
+        if ('' == $email) {
+            throw new RuntimeException('The email is empty');
         }
 
         $vars = [
-            ':email' => $this->c->NormEmail->normalize($provider->userEmail),
+            ':email' => $this->c->NormEmail->normalize($email),
         ];
         $query = 'SELECT pu.uid
             FROM ::providers_users AS pu
@@ -74,7 +73,7 @@ class ProviderUser extends Model
         $count  = \count($result);
 
         if ($count > 1) {
-            throw new RuntimeException("Many entries for '{$provider->userEmail}'");
+            throw new RuntimeException("Many entries for '{$email}'");
         }
 
         return $count ? \array_pop($result) : 0;