Files
Grav-Admin-Plugin/classes/utils.php

39 lines
929 B
PHP
Raw Normal View History

<?php
namespace Grav\Plugin\Admin;
use Grav\Common\Grav;
use Grav\Common\User\User;
/**
* Admin utils class
*
* @license MIT
*/
class Utils
{
/**
* Matches an email to a user
*
* @param $email
*
* @return User
*/
2016-07-07 18:53:37 +02:00
public static function findUserByEmail($email)
{
$account_dir = Grav::instance()['locator']->findResource('account://');
2017-02-26 19:36:01 +01:00
$files = array_diff(scandir($account_dir), ['.', '..']);
foreach ($files as $file) {
if (strpos($file, '.yaml') !== false) {
$user = User::load(trim(substr($file, 0, -5)));
if ($user['email'] == $email) {
return $user;
}
}
}
// If a User with the provided email cannot be found, then load user with that email as the username
return User::load($email);
}
}