Backend\Modules\Users\Engine\Model::getIdByEmail PHP Method

getIdByEmail() public static method

Get the user ID linked to a given email
public static getIdByEmail ( string $email ) : integer
$email string The email for the user.
return integer
    public static function getIdByEmail($email)
    {
        // get user-settings
        $userId = BackendModel::getContainer()->get('database')->getVar('SELECT i.id
             FROM users AS i
             WHERE i.email = ?', array((string) $email));
        // userId or false on error
        return $userId == 0 ? false : (int) $userId;
    }

Usage Example

Example #1
0
 /**
  * The user is allowed on this page
  *
  * @return bool
  */
 private function isUserAllowed()
 {
     // catch the key and e-mail address from GET
     $this->email = urldecode(\SpoonFilter::getGetValue('email', null, ''));
     $this->key = \SpoonFilter::getGetValue('key', null, '');
     // if the email or the key aren't set, redirect the user
     if ($this->email !== '' && $this->key !== '') {
         // fetch the user
         $userId = BackendUsersModel::getIdByEmail($this->email);
         $this->user = new BackendUser($userId);
         $requestTime = $this->user->getSetting('reset_password_timestamp');
         // check if the request was made within 24 hours
         if (time() - $requestTime > 86400) {
             // remove the reset_password_key and reset_password_timestamp usersettings
             BackendUsersModel::deleteResetPasswordSettings($userId);
             // redirect to the login form, with a timeout error
             $this->redirect(BackendModel::createURLForAction('Index', null, null, array('reset' => 'timeout')));
         }
         // check if the provided key matches the one in the user record
         if ($this->key === $this->user->getSetting('reset_password_key')) {
             return true;
         }
     }
     // if we made it here the user is not allowed to access this page
     return false;
 }
All Usage Examples Of Backend\Modules\Users\Engine\Model::getIdByEmail