Frontend\Modules\Profiles\Engine\Authentication::getLoginStatus PHP Method

getLoginStatus() public static method

Get the login/profile status for the given e-mail and password.
public static getLoginStatus ( string $email, string $password ) : string
$email string Profile email address.
$password string Profile password.
return string One of the FrontendProfilesAuthentication::LOGIN_* constants.
    public static function getLoginStatus($email, $password)
    {
        $email = (string) $email;
        $password = (string) $password;
        // get profile id
        $profileId = FrontendProfilesModel::getIdByEmail($email);
        // encrypt password
        $encryptedPassword = FrontendProfilesModel::getEncryptedString($password, FrontendProfilesModel::getSetting($profileId, 'salt'));
        // get the status
        $loginStatus = FrontendModel::getContainer()->get('database')->getVar('SELECT p.status
             FROM profiles AS p
             WHERE p.email = ? AND p.password = ?', array($email, $encryptedPassword));
        return empty($loginStatus) ? self::LOGIN_INVALID : $loginStatus;
    }

Usage Example

Beispiel #1
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         $chkRemember = $this->frm->getField('remember');
         // required fields
         $txtEmail->isFilled(FL::getError('EmailIsRequired'));
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // both fields filled in
         if ($txtEmail->isFilled() && $txtPassword->isFilled()) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // get the status for the given login
                 $loginStatus = FrontendProfilesAuthentication::getLoginStatus($txtEmail->getValue(), $txtPassword->getValue());
                 // valid login?
                 if ($loginStatus !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                     // get the error string to use
                     $errorString = sprintf(FL::getError('Profiles' . \SpoonFilter::toCamelCase($loginStatus) . 'Login'), FrontendNavigation::getURLForBlock('Profiles', 'ResendActivation'));
                     // add the error to stack
                     $this->frm->addError($errorString);
                     // add the error to the template variables
                     $this->tpl->assign('loginError', $errorString);
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // login
             FrontendProfilesAuthentication::login($profileId, $chkRemember->getChecked());
             // update salt and password for Dieter's security features
             FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_logged_in', array('id' => $profileId));
             // query string
             $queryString = urldecode(\SpoonFilter::getGetValue('queryString', null, SITE_URL));
             // redirect
             $this->redirect($queryString);
         }
     }
 }
All Usage Examples Of Frontend\Modules\Profiles\Engine\Authentication::getLoginStatus