/** * process the class * * @since 3.0.0 * * @return string */ public function process() { $specialFilter = new Filter\Special(); $emailFilter = new Filter\Email(); $emailValidator = new Validator\Email(); $loginValidator = new Validator\Login(); $auth = new Auth($this->_request); /* process post */ $postArray = ['password' => $specialFilter->sanitize($this->_request->getPost('password')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')]; /* user and email */ $users = Db::forTablePrefix('users'); if ($emailValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) { $postArray['user'] = $emailFilter->sanitize($this->_request->getPost('user')); $users->where('email', $postArray['user']); } else { if ($loginValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) { $postArray['user'] = $specialFilter->sanitize($this->_request->getPost('user')); $users->where('user', $postArray['user']); } } $user = $users->where('status', 1)->findOne(); /* handle error */ $messageArray = $this->_validate($postArray, $user); if ($messageArray) { return $this->_error(['message' => $messageArray]); } /* handle success */ if ($auth->login($user->id)) { return $this->_success(); } return $this->_error(['message' => $this->_language->get('something_wrong')]); }
/** * testLogin * * @since 2.2.0 * * @param string $login * @param integer $expect * * @dataProvider providerValidatorLogin */ public function testLogin($login = null, $expect = null) { /* setup */ $validator = new Validator\Login(); /* result */ $result = $validator->validate($login); /* compare */ $this->assertEquals($expect, $result); }
/** * validate * * @since 3.0.0 * * @param array $postArray array of the post * * @return array */ protected function _validate($postArray = []) { $loginValidator = new Validator\Login(); $emailValidator = new Validator\Email(); $captchaValidator = new Validator\Captcha(); /* validate post */ $messageArray = []; if (!$postArray['name']) { $messageArray[] = $this->_language->get('name_empty'); } if (!$postArray['user']) { $messageArray[] = $this->_language->get('user_empty'); } else { if ($loginValidator->validate($postArray['user']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('user_incorrect'); } else { if (Db::forTablePrefix('users')->where('user', $postArray['user'])->findOne()->id) { $messageArray[] = $this->_language->get('user_exists'); } } } if (!$postArray['email']) { $messageArray[] = $this->_language->get('email_empty'); } else { if ($emailValidator->validate($postArray['email']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('email_incorrect'); } } if (Db::getSetting('captcha') > 0 && $captchaValidator->validate($postArray['task'], $postArray['solution']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('captcha_incorrect'); } return $messageArray; }
/** * validate the account * * @since 3.0.0 * * @param array $postArray array to be validated * * @return array */ protected function _validateAccount($postArray = []) { $emailValidator = new Validator\Email(); $loginValidator = new Validator\Login(); /* validate post */ $messageArray = []; if (!$postArray['adminName']) { $messageArray[] = $this->_language->get('name_empty'); } if (!$postArray['adminUser']) { $messageArray[] = $this->_language->get('user_empty'); } else { if ($loginValidator->validate($postArray['adminUser']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('user_incorrect'); } } if (!$postArray['adminPassword']) { $messageArray[] = $this->_language->get('password_empty'); } else { if ($loginValidator->validate($postArray['adminPassword']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('password_incorrect'); } } if (!$postArray['adminEmail']) { $messageArray[] = $this->_language->get('email_empty'); } else { if ($emailValidator->validate($postArray['adminEmail']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('email_incorrect'); } } return $messageArray; }