login() public method

login the user
Since: 3.0.0
public login ( integer $userId = null ) : boolean
$userId integer identifier of the user
return boolean
コード例 #1
0
ファイル: Login.php プロジェクト: redaxmedia/redaxscript
 /**
  * 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')]);
 }
コード例 #2
0
ファイル: LogoutTest.php プロジェクト: redaxmedia/redaxscript
 /**
  * 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);
 }
コード例 #3
0
ファイル: AuthTest.php プロジェクト: redaxmedia/redaxscript
 /**
  * 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);
 }