-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Ability to Login with Email
Thanks to @gsumpster for #685 * implemented email-login, close #674 * changed placeholder text * Fix Utils namespace thing * Drop use * Cleanup styling
- Loading branch information
1 parent
3501385
commit 64a88c9
Showing
4 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?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 | ||
* | ||
* @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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters