Beispiel #1
0
 public function loginAction()
 {
     $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
     $this->view->messages = $this->_flashMessenger->getMessages();
     $form = new Application_Form_Login();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             $senha = $form->getValue('senha');
             try {
                 Application_Model_Auth::login($login, $senha);
                 //Redireciona para o Controller protegido
                 return $this->_helper->redirector->goToRoute(array('controller' => 'noticias'), null, true);
             } catch (Exception $e) {
                 //Dados inválidos
                 $this->_helper->FlashMessenger($e->getMessage());
                 $this->_redirect('/auth/login');
             }
         } else {
             $form->populate($data);
         }
     }
 }
 public function indexAction()
 {
     $form = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             // <input name='login'>
             $pass = md5($form->getValue('pass'));
             $adaptateur = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
             $adaptateur->setTableName('membre')->setIdentityColumn('login')->setCredentialColumn('pass')->setIdentity($login)->setCredential($pass);
             if ($adaptateur->authenticate()->isValid()) {
                 // BRAVO
                 $storage = Zend_Auth::getInstance()->getStorage();
                 $mapper = new Application_Model_Mapper_Membre();
                 $membre = $mapper->getByLogin($login);
                 $storage->write($membre);
                 $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/auth.ini');
                 $controller = $config->auth->defaultController;
                 $action = $config->auth->defaultAction;
                 $this->_helper->getHelper('Redirector')->gotoSimple($action, $controller);
             } else {
                 $this->view->msgErreur = "Mauvais login/pass";
                 $form->populate($data);
             }
         } else {
             $form->populate($data);
             $form->buildBootstrapErrorDecorators();
             $this->view->msgErreur = "Veuillez vérifier votre formulaire !";
         }
     }
     $this->view->form = $form;
 }
Beispiel #3
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         //      if ($form->isValid($this->_getAllParams()))
         if ($form->isValid($request->getPost())) {
             $dbAdapter = Zend_Db_Table::getDefaultAdapter();
             $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
             $authAdapter->setTableName('smo_usuario')->setIdentityColumn('usu_rut')->setCredentialColumn('usu_passwd')->setCredentialTreatment('md5(CONCAT(?,usu_passwd_salt))');
             $authAdapter->setIdentity($form->getValue('rut'))->setCredential($form->getValue('pass'));
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 // get all info about this user from the login table  // ommit only the password, we don't need that
                 $userInfo = $authAdapter->getResultRowObject(null, 'password');
                 // the default storage is a session with namespace Zend_Auth
                 $authStorage = $auth->getStorage();
                 $authStorage->write($userInfo);
                 return $this->_helper->redirector->gotoSimple('index', 'index');
                 //$this->_redirect('view/index/index');
             } else {
                 $errorMessage = "Datos Incorrectos, intente de nuevo.";
             }
         }
     }
     $this->view->form = $form;
     $this->view->errorMessage = $errorMessage;
 }
 public function forbiddenAction()
 {
     $this->_helper->layout->setLayout('semAcesso');
     $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
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         //Formulário corretamente preenchido?
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             $senha = $form->getValue('senha');
             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->_redirect('/index/login');
             }
         } else {
             //Formulário preenchido de forma incorreta
             $form->populate($data);
         }
     }
 }
Beispiel #5
0
 /**
  * Action login.
  *
  * @return void
  */
 public function loginAction()
 {
     $this->view->title = "Login";
     $session = new Zend_Session_Namespace('data');
     $auth = Zend_Auth::getInstance();
     $form = new Application_Form_Login();
     if ($auth->hasIdentity()) {
         $this->_redirect('/dashboard');
     }
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $username = $form->getValue('email');
             $password = $form->getValue('password');
             $result = $this->login($username, $password);
             if ($result->isValid()) {
                 $session->attempt = 0;
                 if ($session->url) {
                     $url = $session->url;
                     $session->url = null;
                     $this->_redirect($url);
                 }
                 $this->_redirect('/dashboard');
             }
             $this->view->messages = array('Login failed');
         }
         $session->attempt++;
     }
     if ($this->_hasParam('url')) {
         $path = str_replace('index.php', '', $_SERVER['SCRIPT_NAME']);
         $url = base64_decode($this->_getParam('url'));
         $url = str_replace($path, '', $url);
         $session->url = $url;
     }
     $this->view->form = $form;
 }
Beispiel #6
0
    public function indexAction()
    {
        // action body
        require_once 'Zend/Session/Namespace.php';
        $result1 = 1;
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $loginForm = new Application_Form_Login($_POST);
        if ($this->getRequest()->isPost()) {
            $this->request = $this->getRequest();
            if (isset($_POST['submit']) && $loginForm->isValid($_POST)) {
                $adapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'name', 'password');
                $adapter->setIdentity($loginForm->getValue('username'));
                $adapter->setCredential($loginForm->getValue('password'));
                $result = $adapter->authenticate($adapter);
                if ($result->isValid()) {
                    //new Zend_Session_Namespace();
                    //$this->_helper->FlashMessenger('Erfolgreich angemeldet');
                    //$db = Zend_Registry::get('dbc');
                    $db->query('SET NAMES utf8;');
                    $query = 'SELECT
		                                		user_id, userstate

		                      		FROM
		                                		USERS
					
		                     		WHERE 		name = "' . mysql_real_escape_string($loginForm->getValue('username')) . '";';
                    $stmt = $db->query($query);
                    $result1 = $stmt->fetch();
                    $session = new Zend_Session_Namespace('loggedin');
                    $session->loggedin = $result1['userstate'];
                    $session->loggedin_id = $result1['user_id'];
                    $session->loggedin_user = $loginForm->getValue('username');
                    echo "Anmeldung erfolgreich";
                    //$vision=1;
                    //$this->view->vision = $vision;
                    $loginForm = null;
                    //$this->view->loginForm = $loginForm;
                    $this->redirect('index');
                    //Zend_Session::start();
                    //new Zend_Session_Namespace();
                    //session_start();
                    return;
                } else {
                    echo "Wrong Username or Password";
                }
            }
        }
        $this->view->loginForm = $loginForm;
    }
Beispiel #7
0
 public function loginAction()
 {
     //instancia o formulario de login
     $form = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             /**
              * Instancia o Auth Db Table Adapter
              *
              * Quando se instancia este objeto, precisamos informar as configurações
              * do BD, nome da tabela onde os dados de login estão, o campo do nome
              * do usuário, e o campo da senha na tabela.
              */
             $auth = Zend_Auth::getInstance();
             //$conexao = $this->getInvokeArg('bootstrap')->getDb('db2');
             //Zend_Db_Table::setDefaultAdapter($conexao);
             //$resource = $bootstrap->getPluginResource('multidb');
             //$db1 = $resource->getDb('db1');
             //$db2 = $resource->getDb('db2');
             $auth->clearIdentity();
             $dbAdapter = Zend_Registry::get('db');
             $adapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 'empresa', 'usuario', 'senha');
             // Configura as credencias informadas pelo usuário
             $adapter->setIdentity($form->getValue('txtUserName'));
             $adapter->setCredential($form->getValue('txtPassword'));
             // Cria uma instancia de Zend_Auth
             //$auth = Zend_Auth::getInstance();
             // Tenta autenticar o usuário
             $result = $auth->authenticate($adapter);
             /**
              * Se o usuário for autenticado redireciona para a index e grava seu email,
              * caso contrário exibe uma mensagem de alerta na página
              */
             if ($result->isValid()) {
                 $data = $adapter->getResultRowObject(array('id', 'nome', 'cnpj', 'endereco', 'usuario', 'senha', 'email', 'site', 'perfil', 'contratante'));
                 //$data->listacontratos="1,2";
                 // Armazena os dados do usuário
                 $auth->getStorage()->write($data);
                 //echo "Login efetuado com sucesso";
                 $this->_redirect('/');
             } else {
                 $this->view->message = 'Usuario/senha invalidos. ERRO';
             }
         }
     }
     $this->view->form = $form;
 }
 public function loginAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         return $this->_redirect('/');
     }
     // process the form
     $form = new Application_Form_Login();
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         // check if the user exists
         $user_mapper = new Application_Model_UserMapper();
         $qry = "\n                SElECT *\n                FROM   user\n                WHERE  username = :credential\n                OR     email    = :credential";
         $params = array('credential' => $form->getValue('credential'));
         $user = $user_mapper->query($qry, $params);
         if ($user) {
             $user = new Application_Model_User($user[0]);
             // if the account is not active, prompt the user to activate the account
             if (!$user->getActive()) {
                 $this->_helper->FlashMessenger('User Not Activated');
                 return $this->_redirect('/registration/confirm/id/' . $user->getId());
             }
             // authenticate the user
             $db = Zend_Registry::get('db_default');
             $credential_choice = $params['credential'] == $user->getUsername() ? 'username' : 'email';
             $adapter = new Zend_Auth_Adapter_DbTable($db, 'user', $credential_choice, 'password_hash');
             $adapter->setIdentity($form->getValue('credential'));
             $adapter->setCredential(hash('sha256', $user->getPassword_salt() . $form->getValue('password')));
             $zend_auth = Zend_Auth::getInstance();
             $result = $zend_auth->authenticate($adapter);
             if ($result->isValid()) {
                 // store session information in database
                 $session_mapper = new Application_Model_SessionMapper();
                 $session = new Application_Model_Session(array('user_id' => $user->getId(), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'login_timestamp' => date('Y-m-d H:i:s')));
                 $session_mapper->save($session);
                 // store user information in session variable
                 $session = new Zend_Session_Namespace('user');
                 $session->user = $user->get_array();
                 $this->_helper->FlashMessenger('Successful Login');
                 return $this->_redirect('/');
             } else {
                 echo "Authentication failed.";
             }
         } else {
             echo "Invalid username/email";
         }
     }
     $this->view->form = $form;
 }
 public function loginAction()
 {
     $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
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         // Formulário corretamente preenchido?
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             $senha = $form->getValue('senha');
             $dbAdapter = Zend_Db_Table::getDefaultAdapter();
             // Inicia o adaptador Zend_Auth para banco de dados
             $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
             $authAdapter->setTableName('usuario')->setIdentityColumn('login')->setCredentialColumn('senha')->setCredentialTreatment('SHA1(?)');
             // Define os dados para processar o login
             $authAdapter->setIdentity($login)->setCredential($senha);
             // Efetua o login
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             // Verifica se o login foi efetuado com sucesso
             if ($result->isValid()) {
                 // Armazena os dados do usuário em sessão, apenas
                 // desconsiderando
                 // a senha do usuário
                 $info = $authAdapter->getResultRowObject(null, 'senha');
                 $storage = $auth->getStorage();
                 $storage->write($info);
                 // Redireciona para o Controller protegido
                 return $this->_helper->redirector->goToRoute(array('controller' => 'lab', 'action' => 'select'), null, true);
             } else {
                 // Dados inválidos
                 $this->_helper->FlashMessenger('Usuário ou senha inválidos!');
                 $this->_redirect('/auth/login');
             }
         } else {
             // Formulário preenchido de forma incorreta
             $form->populate($data);
         }
     }
 }
 public function loginAction()
 {
     $this->view->form = $form = new Application_Form_Login();
     if ($this->_request->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $bootstrap = $this->getInvokeArg('bootstrap');
             $resource = $bootstrap->getPluginResource('db');
             $db = $resource->getDbAdapter();
             $adapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'email', 'password', 'SHA1(?)');
             $adapter->setIdentity($form->getValue('email'))->setCredential($form->getValue('password'));
             $result = Zend_Auth::getInstance()->authenticate($adapter);
             if (Zend_Auth::getInstance()->hasIdentity()) {
                 $this->_redirect('post/index');
             } else {
                 $this->_redirect('auth/login');
             }
         }
     }
 }
 public function loginAction()
 {
     // se já estiver logado redireciona para a página inicial
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_helper->redirector('index', 'index');
     }
     $loginForm = new Application_Form_Login();
     $request = $this->getRequest();
     $mensagemDeErro = '';
     if ($request->isPost()) {
         if ($loginForm->isValid($request->getPost())) {
             // Pega o adaptador de autenticação a partir de uma tabela do banco
             $dbAdapter = Zend_Db_Table::getDefaultAdapter();
             $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
             // Define os campos para verificação
             $authAdapter->setTableName('usuario')->setIdentityColumn('email')->setCredentialColumn('senha')->setCredentialTreatment('MD5(?)');
             // pega o usuário e senha enviado via form
             $email = $loginForm->getValue('email');
             $senha = $loginForm->getValue('senha');
             // passa para o adapter os parâmetros a serem validados
             $authAdapter->setIdentity($email)->setCredential($senha);
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             // se o usuário for válido
             if ($result->isValid()) {
                 // armazena todas as informações do usuário com exceção da senha
                 $userInfo = $authAdapter->getResultRowObject(null, 'senha');
                 // prepara armazenamento das informações da sessão
                 $authStorage = $auth->getStorage();
                 $authStorage->write($userInfo);
                 // redireciona para a página inicial
                 $this->_helper->redirector('index', 'index');
             } else {
                 $mensagemDeErro = "Usuário ou senha incorretos";
             }
         }
     }
     $this->view->mensagemDeErro = $mensagemDeErro;
     $this->view->form = $loginForm;
 }
 public function loginAction()
 {
     $form = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->_getAllParams())) {
             $authAdapter = new Zend_Auth_Adapter_DbTable();
             $authAdapter->setTableName('usuarios')->setIdentityColumn('email')->setCredentialColumn('password');
             $authAdapter->setIdentity($form->getValue('email'))->setCredential(md5($form->getValue('password')));
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $namespace = new Zend_Session_Namespace('Zend_Auth');
                 $namespace->setExpirationSeconds(3600);
                 //Inactividad de 1 HR ACA !
                 return $this->_redirect('usuario');
             } else {
                 $form->email->addError('Datos Incorrectos');
             }
         }
     }
     $this->view->form = $form;
 }
 public function indexAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('Nowplaying');
     }
     //uses separate layout without a navigation.
     $this->_helper->layout->setLayout('login');
     $request = $this->getRequest();
     $form = new Application_Form_Login();
     $message = "Please enter your user name and password";
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $authAdapter = $this->getAuthAdapter();
             //get the username and password from the form
             $username = $form->getValue('username');
             $password = $form->getValue('password');
             //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);
                 $tempSess = new Zend_Session_Namespace("referrer");
                 $tempSess->referrer = 'login';
                 $this->_redirect('Nowplaying');
             } else {
                 $message = "Wrong username or password provided. Please try again.";
             }
         }
     }
     $this->view->message = $message;
     $this->view->form = $form;
     $this->view->airtimeVersion = AIRTIME_VERSION;
     $this->view->airtimeCopyright = AIRTIME_COPYRIGHT_DATE;
 }
Beispiel #14
0
 public function loginAction()
 {
     $form = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->_getAllParams())) {
             $authAdapter = new Zend_Auth_Adapter_DbTable();
             $authAdapter->setTableName('users')->setIdentityColumn('username')->setCredentialColumn('password');
             $authAdapter->setIdentity($form->getValue('username'))->setCredential(md5($form->getValue('password')));
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $storage = $auth->getStorage();
                 $dataUser = $authAdapter->getResultRowObject(array('id', 'username', 'realname', 'contact_id', 'role'));
                 $storage->write($dataUser);
                 return $this->_redirect('/dashboard');
             } else {
                 $form->username->addErrorMessage('Datos Incorrectos');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #15
0
 public function loginAction()
 {
     // action body
     //menssagem de erro
     $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
     //if possui usuario
     if (Zend_Auth::getInstance()->getIdentity()) {
         return $this->_helper->redirector->goToRoute(array('controller' => 'perfil'), null, true);
     }
     //Verifica se existem dados de POST
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         //Formul�rio corretamente preenchido?
         if ($form->isValid($data)) {
             $login = $form->getValue('login');
             $senha = $form->getValue('senha');
             try {
                 Application_Model_Auth::login($login, $senha);
                 //Redireciona para o Controller protegido
                 Application_Model_Redirect::redirect();
                 return;
                 //  return $this->_helper->redirector->goToRoute( array('controller' => 'perfil'), null, true);
             } catch (Exception $e) {
                 //Dados inv�lidos
                 $this->_helper->FlashMessenger($e->getMessage());
                 $this->_redirect('/auth/login');
             }
         } else {
             //Formul�rio preenchido de forma incorreta
             $form->populate($data);
         }
     }
 }
Beispiel #16
0
 public function loginAction()
 {
     // action body
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->_redirect('/users/index');
     } else {
         $db = $this->_getParam('user');
         $loginForm = new Application_Form_Login();
         if ($loginForm->isValid($_POST)) {
             $adapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'username', 'password');
             $adapter->setIdentity($loginForm->getValue('username'));
             $pass = md5($loginForm->getValue('password'));
             $adapter->setCredential($pass);
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($adapter);
             $namespace = new Zend_Session_Namespace();
             $namespace->username = $loginForm->getValue('username');
             $namespace->password = $loginForm->getValue('password');
             if ($namespace->username == "amera" && $namespace->password == "amera123") {
                 $namespace->role = "admin";
             } else {
                 $namespace->role = "editor";
             }
             $this->view->username = $namespace->username;
             if ($result->isValid()) {
                 $this->_helper->FlashMessenger('Successful Login');
                 $this->_redirect('/users/index');
                 return;
             } else {
                 $this->view->loginForm = $loginForm;
             }
         }
         $this->view->loginForm = $loginForm;
     }
 }
 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()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $result = $this->_process($form->getValues());
             if ($result->isValid()) {
                 if ($form->getValue('rememberMe') == 1) {
                     // REMEMBER THE SESSION FOR 1 DAYS
                     Zend_Session::rememberMe(self::REMEMBER_DAYS * self::SECONDS_IN_DAY);
                     // 1 days
                 } else {
                     // DO NOT REMEMBER THE SESSION
                     Zend_Session::forgetMe();
                     $session = new Zend_Session_Namespace('Zend_Auth');
                     $session->setExpirationSeconds(self::SECONDS_IN_MINUTE * self::EXPIRATION_MINUTES);
                 }
                 // We're authenticated! Redirect to the home page
                 $this->_helper->redirector('index', 'index');
             } else {
                 foreach ($result->getMessages() as $message) {
                     $this->_helper->getHelper('FlashMessenger')->addMessage($message, 'error');
                     $this->_helper->redirector('login');
                 }
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #19
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 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>";
             }
         }
     }
 }