Since: 3.0.0
Author: Henry Ruhs
Exemple #1
0
 /**
  * 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')]);
 }
Exemple #2
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $auth = new Auth($this->_request);
     $auth->init();
     /* handle success */
     if ($auth->logout()) {
         return $this->_success();
     }
     return $this->_error();
 }
 /**
  * testProcess
  *
  * @since 3.0.0
  *
  * @param array $authArray
  * @param string $expect
  *
  * @dataProvider providerProcess
  */
 public function testProcess($authArray = [], $expect = null)
 {
     /* setup */
     $auth = new Auth($this->_request);
     $logoutController = new Controller\Logout($this->_registry, $this->_language, $this->_request);
     if ($authArray['login']) {
         $auth->login(1);
     }
     if ($authArray['logout']) {
         $auth->logout();
     }
     /* actual */
     $actual = $logoutController->process();
     /* compare */
     $this->assertEquals($expect, $actual);
 }
Exemple #4
0
 /**
  * testGetFilter
  *
  * @since 3.0.0
  *
  * @param string $groups
  * @param boolean $expect
  *
  * @dataProvider providerGetFilter
  */
 public function testGetFilter($groups = null, $expect = null)
 {
     /* setup */
     Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('groups', $groups)->save();
     $auth = new Auth($this->_request);
     $auth->login(1);
     /* actual */
     $actual = $auth->getFilter();
     /* compare */
     $this->assertEquals($expect, $actual);
 }
Exemple #5
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $auth = new Auth(Request::getInstance());
     $tableArray = ['categories', 'articles', 'extras', 'comments', 'groups', 'users'];
     /* set user */
     $auth->setUser('name', 'Demo');
     $auth->setUser('user', 'demo');
     $auth->setUser('email', 'demo@localhost');
     /* set permission */
     foreach ($tableArray as $value) {
         $auth->setPermission($value, [1, 2, 3]);
     }
     $auth->setPermission('settings', [1]);
     /* save user and permission */
     $auth->save();
     /* handle success */
     if ($auth->getStatus()) {
         return self::_success();
     }
     return self::_error();
 }