Redaxscript\Controller\Login::process PHP Method

process() public method

process the class
Since: 3.0.0
public process ( ) : string
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')]);
    }

Usage Example

Example #1
0
 /**
  * testProcess
  *
  * @since 3.0.0
  *
  * @param array $postArray
  * @param array $hashArray
  * @param array $userArray
  * @param string $expect
  *
  * @dataProvider providerProcess
  */
 public function testProcess($postArray = [], $hashArray = [], $userArray = [], $expect = null)
 {
     /* setup */
     Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('status', $userArray['status'])->save();
     $this->_request->set('post', $postArray);
     $this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
     $loginController = new Controller\Login($this->_registry, $this->_language, $this->_request);
     /* actual */
     $actual = $loginController->process();
     /* compare */
     $this->assertEquals($expect, $actual);
 }