findUserByEmail() public static method

Matches an email to a user
public static findUserByEmail ( $email ) : Grav\Common\User\User
$email
return Grav\Common\User\User
Example #1
0
 /**
  * Authenticate user.
  *
  * @param  array $data Form data.
  * @param  array $post Additional form fields.
  *
  * @return bool
  */
 public function authenticate($data, $post)
 {
     if (!$this->user->authenticated && isset($data['username']) && isset($data['password'])) {
         // Perform RegEX check on submitted username to check for emails
         if (filter_var($data['username'], FILTER_VALIDATE_EMAIL)) {
             $user = AdminUtils::findUserByEmail($data['username']);
         } else {
             $user = User::load($data['username']);
         }
         //default to english if language not set
         if (empty($user->language)) {
             $user->set('language', 'en');
         }
         if ($user->exists()) {
             $user->authenticated = true;
             // Authenticate user.
             $result = $user->authenticate($data['password']);
             if (!$result) {
                 return false;
             }
         }
     }
     $action = [];
     if ($user->authorize('admin.login')) {
         $this->user = $this->session->user = $user;
         /** @var Grav $grav */
         $grav = $this->grav;
         unset($this->grav['user']);
         $this->grav['user'] = $user;
         $this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info');
         $grav->redirect($post['redirect']);
         return true;
         //never reached
     }
     return false;
 }