Files
Grav-Admin-Plugin/classes/utils.php
Andy Miller f361addd60 Feature/admin fragmentation (#856)
* Separated Admin Controller into a generic and extendable Base controller. Added Autoload for properly loading classes

* Implemented custom class loader to force lowercase

* Removed composer autoloader for classes

* Updates

* Ability to pass custom upload URL for files

* Added new onAdminCanSave event for 3rd party plugins

* Moved files upload GC in onOutputGenerated event

* Cleanup

* Moved autoloader so it is always registering

* Fixed onOutputGenerated event location

* Moved `taskRemoveFileFromBlueprint`,  `taskRemoveMedia `, `canEditMedia` methods to admin base controller

* Allow to globally define `blueprint_type` and `file_url_remove` for the file field

* Moved `isMultilang()` into base controller

* Properly generate thumbnails in proportions for file fields

* Simplified execute restrictions with blacklist
2016-11-07 09:54:10 -07:00

39 lines
923 B
PHP

<?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
*/
public static function findUserByEmail($email)
{
$account_dir = Grav::instance()['locator']->findResource('account://');
$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);
}
}