Frontend\Modules\Profiles\Engine\Model::existsByEmail PHP Method

existsByEmail() public static method

Check if a profile exists by email address.
public static existsByEmail ( string $email, integer $ignoreId = null ) : boolean
$email string Email to check for existence.
$ignoreId integer Profile id to ignore.
return boolean
    public static function existsByEmail($email, $ignoreId = null)
    {
        return (bool) FrontendModel::getContainer()->get('database')->getVar('SELECT 1
             FROM profiles AS p
             WHERE p.email = ? AND p.id != ?
             LIMIT 1', array((string) $email, (int) $ignoreId));
    }

Usage Example

Beispiel #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // get profile id using the filled in email
                     $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
                     // get profile
                     $profile = FrontendProfilesModel::get($profileId);
                     // must be inactive
                     if ($profile->getStatus() != FrontendProfilesAuthentication::LOGIN_INACTIVE) {
                         $txtEmail->addError(FL::getError('ProfileIsActive'));
                     }
                 } else {
                     // email don't exist
                     $txtEmail->addError(FL::getError('EmailIsInvalid'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // activation URL
             $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $profile->getSetting('activation_key');
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_resend_activation', array('id' => $profileId));
             // send email
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($profile->getEmail() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Profiles/Layout/Templates/Mails/Register.html.twig', $mailValues, true);
             $this->get('mailer')->send($message);
             // redirect
             $this->redirect(SITE_URL . $this->URL->getQueryString() . '?sent=true');
         } else {
             $this->tpl->assign('resendActivationHasError', true);
         }
     }
 }
All Usage Examples Of Frontend\Modules\Profiles\Engine\Model::existsByEmail