Beispiel #1
0
    public function indexAction()
    {

        //Redireciona se acaso o usuário já estiver logado no sistema
        if ($this->_auth->getIdentity()) {
            $this->autoRedirect();
        }

        if ($_POST) {
            $validAuth = null;
            $username = null;
            $password = null;

            // Valida o formulário
            if ($this->_form->isValid($this->_request->getParams())) {
                $username = $this->_request->getParam('username');
                $password = $this->_request->getParam('password');
            }


            if ($username && $password) {
                // Tenta fazer a autenticação
                if ($this->_bsnUser->authenticate($username, $password)) {
                    $this->autoRedirect();
                } else {
                    $this->_form->getElement('username')->addError('Login e/ou Senha inválidos.');
                    $this->_form->getElement('username')->setValue($_POST['username']);
                }
            }
        }

        $this->view->form = $this->_form;
    }
 public function loginAction()
 {
     // action body
     $request = $this->getRequest();
     $form = new Application_Form_Login();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $bootstrap = $this->getInvokeArg('bootstrap');
             $dbAdapter = $bootstrap->getResource('db');
             $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 'user', 'name', 'password');
             $data = $form->getValidValues($request->getPost());
             $authAdapter->setIdentity($data['name']);
             $password = sha1($data['password']);
             $authAdapter->setCredential($password);
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $user = $authAdapter->getResultRowObject(null, 'password');
                 $storage = $auth->getStorage();
                 $storage->write($user);
                 if ($user->confirmed == 1) {
                     $this->_redirect('dashboard');
                     // Redirect to dashboard
                 } else {
                     Zend_Auth::getInstance()->clearIdentity();
                     $this->view->errors = array('You\'re registration is not yet confirmed');
                 }
             } else {
                 $form->getElement('password')->addError('Invalid password.');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #3
0
 public function indexAction()
 {
     global $CC_CONFIG;
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('Showbuilder');
     }
     //uses separate layout without a navigation.
     $this->_helper->layout->setLayout('login');
     $error = false;
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $this->view->headScript()->appendFile($baseUrl . '/js/airtime/login/login.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $form = new Application_Form_Login();
     $message = "Please enter your user name and password";
     if ($request->isPost()) {
         // if the post contains recaptcha field, which means form had recaptcha field.
         // Hence add the element for validation.
         if (array_key_exists('recaptcha_response_field', $request->getPost())) {
             $form->addRecaptcha();
         }
         if ($form->isValid($request->getPost())) {
             //get the username and password from the form
             $username = $form->getValue('username');
             $password = $form->getValue('password');
             if (Application_Model_Subjects::getLoginAttempts($username) >= 3 && $form->getElement('captcha') == NULL) {
                 $form->addRecaptcha();
             } else {
                 $authAdapter = Application_Model_Auth::getAuthAdapter();
                 //pass to the adapter the submitted username and password
                 $authAdapter->setIdentity($username)->setCredential($password);
                 $auth = Zend_Auth::getInstance();
                 $result = $auth->authenticate($authAdapter);
                 if ($result->isValid()) {
                     //all info about this user from the login table omit only the password
                     $userInfo = $authAdapter->getResultRowObject(null, 'password');
                     //the default storage is a session with namespace Zend_Auth
                     $authStorage = $auth->getStorage();
                     $authStorage->write($userInfo);
                     Application_Model_LoginAttempts::resetAttempts($_SERVER['REMOTE_ADDR']);
                     Application_Model_Subjects::resetLoginAttempts($username);
                     $tempSess = new Zend_Session_Namespace("referrer");
                     $tempSess->referrer = 'login';
                     $this->_redirect('Showbuilder');
                 } else {
                     $message = "Wrong username or password provided. Please try again.";
                     Application_Model_Subjects::increaseLoginAttempts($username);
                     Application_Model_LoginAttempts::increaseAttempts($_SERVER['REMOTE_ADDR']);
                     $form = new Application_Form_Login();
                     $error = true;
                 }
             }
         }
     }
     $this->view->message = $message;
     $this->view->error = $error;
     $this->view->form = $form;
     $this->view->airtimeVersion = Application_Model_Preference::GetAirtimeVersion();
     $this->view->airtimeCopyright = AIRTIME_COPYRIGHT_DATE;
     if (isset($CC_CONFIG['demo'])) {
         $this->view->demo = $CC_CONFIG['demo'];
     }
 }
 public function indexAction()
 {
     $this->_helper->page->doCanonicalRedirect('go');
     //if logged in user trys to go to the login page - redirect him to the main page
     if (Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_PAGE_PROTECTED)) {
         $this->_redirect($this->_helper->website->getUrl());
     }
     $loginForm = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         if ($loginForm->isValid($this->getRequest()->getParams())) {
             $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('dbAdapter'), 'user', 'email', 'password', 'MD5(?)');
             $authAdapter->setIdentity($loginForm->getValue('email'));
             $authAdapter->setCredential($loginForm->getValue('password'));
             $authResult = $authAdapter->authenticate();
             if ($authResult->isValid()) {
                 $authUserData = $authAdapter->getResultRowObject(null, 'password');
                 if (null !== $authUserData) {
                     $user = new Application_Model_Models_User((array) $authUserData);
                     $user->setLastLogin(date(Tools_System_Tools::DATE_MYSQL));
                     $user->setIpaddress($_SERVER['REMOTE_ADDR']);
                     $this->_helper->session->setCurrentUser($user);
                     Application_Model_Mappers_UserMapper::getInstance()->save($user);
                     unset($user);
                     $this->_helper->cache->clean();
                     if ($authUserData->role_id == Tools_Security_Acl::ROLE_MEMBER) {
                         $this->_memberRedirect();
                     }
                     if (isset($this->_helper->session->redirectUserTo)) {
                         $this->_redirect($this->_helper->website->getUrl() . $this->_helper->session->redirectUserTo, array('exit' => true));
                     }
                     $this->_redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $this->_helper->website->getUrl());
                 }
             }
             $signInType = $this->getRequest()->getParam('singintype');
             if ($signInType && $signInType == Tools_Security_Acl::ROLE_MEMBER) {
                 $this->_memberRedirect(false);
             }
             $this->_checkRedirect(false, array('email' => 'There is no user with such login and password.'));
         } else {
             $this->_checkRedirect(false, array('email' => 'Login should be a valid email address'));
         }
     } else {
         //getting available system translations
         $this->view->languages = $this->_helper->language->getLanguages();
         //getting messages
         $errorMessages = $this->_helper->flashMessenger->getMessages();
         if (!empty($errorMessages)) {
             foreach ($errorMessages as $message) {
                 foreach ($message as $elementName => $msg) {
                     $loginForm->getElement($elementName)->setAttribs(array('class' => 'notvalid', 'title' => $msg));
                 }
             }
         }
         $this->view->messages = $this->_helper->flashMessenger->getMessages();
         //unset url redirect set from any login widget
         unset($this->_helper->session->redirectUserTo);
         $loginForm->removeDecorator('HtmlTag');
         $loginForm->setElementDecorators(array('ViewHelper', 'Errors', 'Label', array('HtmlTag', array('tag' => 'p'))));
         $this->view->loginForm = $loginForm;
     }
 }
 public function loginAction()
 {
     $this->_helper->layout->setLayout('login');
     $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
     $this->view->messages = $this->_flashMessenger->getMessages();
     $form = new Application_Form_Login();
     $this->view->form = $form;
     //Verifica se existem dados de POST
     Zend_Registry::get('logger')->log("antes verificacao loginAction", Zend_Log::INFO);
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         //Formulário corretamente preenchido?
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             $senha = $form->getValue('senha');
             Zend_Registry::get('logger')->log("senha valida", Zend_Log::INFO);
             try {
                 Application_Model_Auth::login($login, $senha);
                 //Redireciona para o Controller protegido
                 return $this->_helper->redirector->goToRoute(array('controller' => 'index'), null, true);
             } catch (Exception $e) {
                 //Dados inválidos
                 //$this->_helper->FlashMessenger($e->getMessage());
                 $this->view->mensagem = "Usuário ou senha incorreto";
                 $this->view->erro = 1;
                 $this->view->mensagemExcecao = $e->getMessage();
                 //$this->_redirect('/index/login');
             }
         } else {
             //Formulário preenchido de forma incorreta
             $form->populate($data);
             Zend_Registry::get('logger')->log("formulario inválido", Zend_Log::INFO);
             $arrMessages = $form->getMessages();
             foreach ($arrMessages as $field => $arrErrors) {
                 $this->view->erro = 1;
                 $this->view->mensagem = $this->view->mensagem . $form->getElement($field)->getLabel() . $this->view->formErrors($arrErrors) . "<br>";
             }
         }
     }
 }