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;
}