Beispiel #1
0
 public function loginAction()
 {
     // uzytkownik jest juz zalogowany, przekierujmy go na strone glowna
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('/');
     }
     // zapisanie do sesji informacji o adresie powrotu
     $session = new Zend_Session_Namespace('signreferer');
     if (!isset($session->referer) && isset($_SERVER['HTTP_REFERER'])) {
         // sprawdzenie, czy referer pochodzi z tej samej domeny
         if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) == $_SERVER['HTTP_HOST']) {
             $session->referer = $_SERVER['HTTP_REFERER'];
         }
     }
     $form = new Application_Form_LogowanieDuze();
     $postData = $this->getRequest()->getPost();
     if ($postData) {
         //            var_dump($postData); die;
         if ($form->isValid($postData)) {
             // stworzenie obiektu Zend_Auth
             $auth = Zend_Auth::getInstance();
             $authAdapter = new Zend_Auth_Adapter_DbTable(null, 'ts_wydania_prenumerata_users_pl', 'username', 'password', 'SHA1(CONCAT(salt, salt, ?, 69)) AND czy_aktywne="T"');
             //$authAdapter->setIdentityColumn('username');
             $authAdapter->setIdentity($form->getValue('username'));
             $authAdapter->setCredential($form->getValue('password'));
             $result = $auth->authenticate($authAdapter);
             $auth = Zend_Auth::getInstance();
             if ($auth->getIdentity()) {
                 $user = TS_Auth::getFullIdentity($auth->getIdentity());
                 $rememberHashTag = TS_Auth::getSalt3();
                 $User = new Application_Model_DbTable_UzytkownicyWww();
                 $newData = array('data_ostatniego_logowania' => new Zend_Db_Expr('NOW()'), 'salt' => $rememberHashTag);
                 $User->update($newData, array('id = ?' => $user->id));
                 setcookie('rememberUser', $rememberHashTag, time() + 10 * 365 * 24 * 60 * 60, '/', $_SERVER['SERVER_NAME']);
                 if ($result->isValid()) {
                     // powrót do linku sprzed logowania
                     $returnUrl = '/';
                     if (isset($session->referer)) {
                         $returnUrl = $session->referer;
                     }
                     unset($session->referer);
                     return $this->_redirect($returnUrl);
                     /*
                                             return $this->_helper->redirector(
                                                 'index',
                                                 'index',
                                                 'default'
                                             );*/
                 }
             }
             // nadpisanie formularza duzym formularzem
             $form = new Application_Form_LogowanieDuze();
             $form->populate($postData);
             //                $form->password->addError('Błędna próba logowania!');
         } else {
             if ($form->getErrors("username")) {
                 $form->getElement("username")->setAttrib("class", "form-control auth-error");
             }
             if ($form->getErrors("password")) {
                 $form->getElement("password")->setAttrib("class", "form-control auth-error");
             }
         }
     }
     //return $this->_helper->redirector('brakautoryzacji', 'user', null, array('komunikat'=>"błędne dane"));
     $this->view->form = $form;
     $this->view->googleAuthUrl = TBS\Auth\Adapter\Google::getAuthorizationUrl();
     $this->view->googleAuthUrlOffline = TBS\Auth\Adapter\Google::getAuthorizationUrl(true);
     $this->view->facebookAuthUrl = TBS\Auth\Adapter\Facebook::getAuthorizationUrl();
     $this->view->twitterAuthUrl = \TBS\Auth\Adapter\Twitter::getAuthorizationUrl();
     $this->view->instagramAuthUrl = \TBS\Auth\Adapter\Instagram::getAuthorizationUrl();
 }