Beispiel #1
0
 public function testInit()
 {
     $this->sessionMock->expects($this->once())->method('setLifetime')->will($this->returnSelf());
     $this->sessionMock->expects($this->once())->method('setSessionName')->will($this->returnSelf());
     $this->translatorMock->expects($this->once())->method('loadTranslations');
     $this->app->init();
     $this->assertEquals(\Magelight\App::DEFAULT_LANGUAGE, $this->app->getLang());
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function initBlock()
 {
     $currentUserId = \Magelight\Http\Session::getInstance()->get('user_id', false);
     if ($currentUserId && ($userData = \Magelight\Auth\Models\User::find($currentUserId)->asArray())) {
         $this->set('user_id', $currentUserId);
         $this->set('user_data', $userData);
     }
     return parent::initBlock();
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function initBlock()
 {
     $currentUserId = \Magelight\Http\Session::getInstance()->get('user_id');
     if (!empty($currentUserId)) {
         if ($user = \Magelight\Auth\Models\User::find($currentUserId)) {
             $userData = $user->asArray();
             $this->setGlobal('user_data', $userData);
         }
     }
     $document = \Magelight\Core\Blocks\Document::getInstance();
     $document->addMeta(['http-equiv' => "content-type", 'content' => "text/html; charset=utf-8"]);
     $document->addCss('Magelight/Core/static/css/bootstrap.css');
     $document->addCss('Magelight/Core/static/css/hint.css');
     $document->addJs('Magelight/Core/static/js/jquery.js');
     $document->addJs('Magelight/Core/static/js/bootstrap.min.js');
     return parent::initBlock();
 }
Beispiel #4
0
 /**
  * Load user data from session
  *
  * @return Form
  */
 public function loadFromSession()
 {
     $data = \Magelight\Http\Session::getInstance()->get('forms-' . $this->getAttribute('name'), []);
     if (!empty($data)) {
         $this->requestFields = $data;
     }
     return $this;
 }
Beispiel #5
0
 public function testToken()
 {
     $this->controller->init();
     $sessionMock = $this->getMock(\Magelight\Http\Session::class, [], [], '', false);
     \Magelight\Http\Session::forgeMock($sessionMock);
     $sessionMock->expects($this->once())->method('set')->with(\Magelight\Controller::DEFAULT_TOKEN_SESSION_INDEX, $this->matchesRegularExpression('/[\\d]+/i'));
     $this->controller->generateToken();
     $sessionMock->expects($this->any())->method('get')->with(\Magelight\Controller::DEFAULT_TOKEN_SESSION_INDEX, null)->will($this->returnValue(123456789));
     $this->assertTrue($this->controller->checkToken(123456789));
     $this->assertFalse($this->controller->checkToken(987654321));
 }
Beispiel #6
0
 /**
  * Get session object
  *
  * @return Http\Session
  */
 public function session()
 {
     return \Magelight\Http\Session::getInstance();
 }
Beispiel #7
0
 /**
  * Shutdown application handler
  * @codeCoverageIgnore
  */
 public function shutdown()
 {
     \Magelight\Http\Session::getInstance()->close();
 }
Beispiel #8
0
 /**
  * Check is current user admin user
  *
  * @return bool
  */
 public function isCurrentUserAdmin()
 {
     $userId = \Magelight\Http\Session::getInstance()->get('user_id');
     $model = \Magelight\Admin\Models\AdminUser::findBy('user_id', $userId);
     return !empty($model);
 }
Beispiel #9
0
 /**
  * Check is captcha correct
  *
  * @param string $code
  * @return bool
  */
 public function check($code)
 {
     if ($this->case_sensitive) {
         return $code === \Magelight\Http\Session::getInstance()->get($this->session_code, null);
     }
     $check = \Magelight\Http\Session::getInstance()->get($this->session_code, null);
     $result = strtolower($code) == strtolower($check);
     \Magelight\Http\Session::getInstance()->unsetData($this->session_code);
     return $result;
 }