Author: M_AbuAjaj Date : 06/11/14
Inheritance: extends Zend_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;
 }
 public function loginAction()
 {
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $formLogin = new Application_Form_Login();
     if ($this->getRequest()->isPost()) {
         foreach ($this->_request->getPost('dataPost') as $dataArray) {
             $name = $dataArray['name'];
             $formDataForValidation["{$name}"] = $dataArray['value'];
         }
         if ($formLogin->isValid($formDataForValidation)) {
             $user = $formDataForValidation['email'];
             $password = $formDataForValidation['password'];
             $adapter = new Zend_Auth_Adapter_DbTable(null, 'users', 'email', 'password');
             $adapter->setIdentity($user);
             $adapter->setCredential($password);
             Zend_Session::regenerateId();
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($adapter);
             if ($result->isValid()) {
                 $user = $adapter->getResultRowObject();
                 $auth->getStorage()->write($user);
                 $this->_helper->json(0);
             } else {
                 $this->_helper->json(1);
             }
         } else {
             $this->_helper->json(1);
         }
     }
 }
 public function loginAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $storage = new Zend_Auth_Storage_Session();
         $storage->clear();
     }
     $users = new Application_Model_User();
     $form = new Application_Form_Login();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             $auth = Zend_Auth::getInstance();
             $authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(), 'user');
             $authAdapter->setIdentityColumn('name')->setCredentialColumn('password');
             $authAdapter->setIdentity($data['name'])->setCredential($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $storage = new Zend_Auth_Storage_Session();
                 $storage->write($authAdapter->getResultRowObject(array('id', 'name', 'image')));
                 if ($auth->getIdentity()->name == 'admin') {
                     $this->redirect("Order/adminhome");
                 } elseif ($auth->getIdentity()->name != 'admin') {
                     $this->redirect("Order/adduserorder");
                 }
             } else {
                 $this->view->errorMessage = "Invalid username or password. Please try again.";
             }
         }
     }
 }
 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
 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;
 }
Beispiel #6
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;
 }
 /**
  * Load login form
  */
 public function loginFormsLoader($request)
 {
     // login form
     $login_form = new Application_Form_Login();
     $this->view->login_form = $login_form;
     $modal_login_form = new Application_Form_Login();
     $modal_login_form->setName('modal_login');
     $this->view->modal_login_form = $modal_login_form;
     if ($request->isPost() && isset($_POST['identifier']) && $_POST['identifier'] == 'Login') {
         $login_form = $this->submitLoginForm($login_form);
     }
     // register form
     $register_form = new Application_Form_Register();
     $this->view->register_form = $register_form;
     $modal_register_form = new Application_Form_Register();
     $modal_register_form->setName('modal_register');
     $this->view->modal_register_form = $modal_register_form;
     if ($request->isPost() && isset($_POST['identifier']) && $_POST['identifier'] == 'Register') {
         $register_form = $this->submitRegisterForm($register_form);
     }
     // lost password form
     $lostpassword_form = new Application_Form_LostPassword();
     $this->view->lostpassword_form = $lostpassword_form;
     $modal_lostpassword_form = new Application_Form_LostPassword();
     $modal_lostpassword_form->setName('modal_lostpassword');
     $this->view->modal_lostpassword_form = $modal_lostpassword_form;
     if ($request->isPost() && isset($_POST['identifier']) && $_POST['identifier'] == 'LostPassword') {
         $lostpassword_form = $this->submitLostPasswordForm($lostpassword_form);
     }
 }
Beispiel #8
0
    public function loggedInAs()
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $user = $auth->getIdentity();
            if (!isset($user->username)) {
                $auth->clearIdentity();
                $info = 'logout';
                return $info;
            }
            $logoutUrl = $this->view->url(array('controller' => 'auth', 'action' => 'logout'), null, true);
            $url = $this->view->url(array('controller' => 'user', 'action' => 'edit', 'id' => $user->id));
            $info = '<div class ="menuButton"><span class="menu">' . $user->username . '</span>';
            $info .= '<ul> 
					<li><a href="' . $url . '">Mon profil</a></li>
					<li class="separator">​</li>
					<li><a href="' . $logoutUrl . '" class="logout">se déconnecter</a></li>
					</ul></div>';
            return $info;
        }
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        if ($controller == 'auth' && $action == 'index') {
            return '';
        }
        $form = new Application_Form_Login();
        $loginUrl = $this->view->url(array('controller' => 'auth', 'action' => 'index'), null, true);
        $info = '<div class ="menuButton"><span class="menu"> Se connecter </span><ul><li class="form">' . $form->setAction($loginUrl) . '</li></ul></div>';
        return $info;
        //$loginUrl = $this->view->url(array('controller'=>'auth', 'action'=>'index'));
        //return '<a href="'.$loginUrl.'">Login</a>';
    }
Beispiel #9
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);
         }
     }
 }
Beispiel #10
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->_request;
     $auth = Zend_Auth::getInstance();
     if ($request->isPost()) {
         $data = $request->getPost();
         if ($form->isValid($data)) {
             $data = $form->getValues();
             $login = Application_Model_Login::login($data['email'], $data['senha']);
             if ($login === true) {
                 $this->redirect('/index');
             } else {
                 $this->_helper->FlashMessenger->addMessage($login);
                 $this->view->messages = $this->_helper->FlashMessenger->getMessages();
                 $form->populate($data);
             }
         }
     } else {
         $this->view->messages = $this->_helper->FlashMessenger->getMessages();
     }
     if ($auth->hasIdentity()) {
         $this->redirect('/index');
     }
     $this->view->form = $form;
     $this->view->logourl = $this->_custom['logourl'];
     $this->view->company_name = $this->_custom['company_name'];
 }
Beispiel #11
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 indexAction()
 {
     if ($this->auth->hasIdentity()) {
         $this->_helper->redirector('index', 'index');
     }
     $translator = Zend_Registry::get('container')->getService('translator');
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $values = $form->getValues();
         $adapter = $this->_helper->service('auth.adapter');
         $adapter->setEmail($values['email'])->setPassword($values['password']);
         $result = $this->auth->authenticate($adapter);
         if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
             $expire = null;
             if (!empty($values['remember_me'])) {
                 // set expire to 10 years in the future
                 $expire = time() + 10 * 365 * 24 * 60 * 60;
             }
             setcookie('NO_CACHE', '1', $expire, '/', '.' . $this->extractDomain($_SERVER['HTTP_HOST']));
             if (isset($values['_target_path'])) {
                 $this->_helper->redirector->gotoUrl($values['_target_path']);
             }
             $this->_helper->redirector('index', 'dashboard');
         } else {
             $form->addError($translator->trans("Invalid credentials"));
         }
     }
     $this->view->form = $form;
 }
Beispiel #13
0
 public function forgotPasswordAction()
 {
     $this->view->pageHeading = "Forgot Password";
     $request = $this->getRequest();
     $this->view->form = $form = new Application_Form_Login();
     $elements = $form->getElements();
     $form->clearDecorators();
     foreach ($elements as $element) {
         $element->removeDecorator('label');
         $element->removeDecorator('Errors');
     }
     $form->removeElement('password');
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $params = $request->getParams();
             $user = new Application_Model_User();
             $user = $user->fetchRow("email='{$params['email']}'");
             if ($user) {
                 $auth = new Base_Auth_Auth();
                 $auth->recoverPassword($user);
                 $this->_flashMessenger->addMessage(array('success' => 'Your password has been reset. Please check your email.'));
                 $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/index/login'));
             } else {
                 $this->_flashMessenger->addMessage(array('error' => "Invalid email address!"));
                 $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/index/forgot-password'));
             }
         } else {
             $this->view->email_msg = array_pop($form->getMessages('email'));
         }
     }
 }
 public function loginAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_helper->redirector('index', 'index', 'default');
     }
     $form = new Application_Form_Login();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
             $authAdapter->setTableName('users')->setIdentityColumn('login')->setCredentialColumn('pass');
             $username = $this->getRequest()->getPost('login');
             $password = $this->getRequest()->getPost('pass');
             $authAdapter->setIdentity($username)->setCredential(md5($password));
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $identity = $authAdapter->getResultRowObject();
                 $authStorage = $auth->getStorage();
                 $authStorage->write($identity);
                 $user = Zend_Auth::getInstance()->getIdentity();
                 if ($user->role == 'admin') {
                     $this->_helper->redirector('index', 'index', 'admin');
                 } else {
                     $this->_helper->redirector('index', 'index', 'default');
                 }
             } else {
                 $this->view->errMessage = 'Вы ввели неверное имя пользователя или пароль!';
             }
         }
     }
 }
Beispiel #15
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             // do something here to log in
         }
     }
     $this->view->form = $form;
 }
 public function formAuth()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $auth = Zend_Auth::getInstance()->getIdentity();
         echo 'Olá, <strong>' . $this->view->escape($auth->nome) . '</strong>' . ' | <a href="' . $this->view->baseUrl('auth/logout') . '">Sair</a>';
     } else {
         $form = new Application_Form_Login();
         $form->setAction($this->view->baseUrl('auth/login'));
         echo $form;
     }
 }
Beispiel #17
0
 public function loginAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             if ($this->_process($form->getValues())) {
                 $this->_helper->redirector('index', 'index');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #18
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             if ($this->_process($form->getValues())) {
                 //success means authenticate criteria has been met
                 $this->_helper->redirector('setparam', 'multi');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #19
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             if ($this->_process($form->getValues())) {
                 // We're authenticated! Redirect to the home page
                 $this->_helper->redirector('index', 'index');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #20
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->_helper->layout->setLayout('layout_login');
     $form = new Application_Form_Login();
     $params = $this->_request->getParams();
     if ($this->_request->isPost() && $form->isValid($params)) {
         $_usuario = new Application_Model_Usuario();
         $loginValido = $_usuario->autenticar($form->getValues());
         if ($loginValido) {
             $this->_redirect('/');
         } else {
             $this->_helper->FlashMessenger('Usuario o contraseña invalido');
             $this->_redirect('/index/login');
         }
     }
     $this->view->form = $form;
 }
 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;
 }
 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);
         }
     }
 }
Beispiel #25
0
 public function loginAction()
 {
     $form = new Application_Form_Login();
             $request = $this->getRequest();
             if ($request->isPost()) {
                 if ($form->isValid($request->getPost())) {
                     if ($this->_process($form->getValues())) {
                         // We're authenticated! Redirect to the home page
                         
                         Log_Admin::GoodEnter($form->getValues());
                         $this->_helper->redirector('index', 'hna');
                     } else {
                         Log_Admin::BadEnter($form->getValues());
                         echo "Ошибка! Проверьте правильность введенных данных!";
                     }
                 }
             }
             $this->view->form = $form;
 }
Beispiel #26
0
 public function indexAction()
 {
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             if ($this->_process($form->getValues())) {
                 // We're authenticated! Redirect to the home page
                 $this->_helper->redirector('index', 'index');
             } else {
                 $this->_flashMessage('Login failed');
             }
         }
     }
     $this->view->form = $form;
     $flashMessenger = $this->_helper->FlashMessenger;
     $flashMessenger->setNamespace('actionErrors');
     $this->view->actionErrors = $flashMessenger->getMessages();
 }
 public function loginAction()
 {
     $loginForm = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost() && $loginForm->isValid($request->getPost())) {
         $service = new Application_Model_Service();
         $data = $request->getPost();
         if ($service->login($data['username'], $data['password'])) {
             if ($request->isXmlHttpRequest()) {
                 $this->view->success = true;
             } else {
                 $this->_redirect("/");
             }
         } else {
             $this->view->error = " Bad Credentials ";
         }
     }
     $this->view->form = $loginForm;
 }
 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');
             }
         }
     }
 }
Beispiel #29
0
 public function indexAction()
 {
     if ($this->auth->hasIdentity()) {
         $this->_helper->redirector('index', 'index');
     }
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $values = $form->getValues();
         $adapter = $this->_helper->service('auth.adapter');
         $adapter->setEmail($values['email'])->setPassword($values['password']);
         $result = $this->auth->authenticate($adapter);
         if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
             $this->_helper->redirector('index', 'dashboard');
         } else {
             $form->addError($this->view->translate("Invalid credentials"));
         }
     }
     $this->view->form = $form;
 }
 public function loginAction()
 {
     Zend_Registry::get('log')->info(__METHOD__);
     $this->_helper->layout()->disableLayout();
     $form = new Application_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $userservice = App_Service_Manager::getService('user');
             if ($user = $userservice->isValid($form->getValues())) {
                 // We're authenticated! Redirect to the home page
                 Zend_Auth::getInstance()->getStorage()->write($user);
                 $acl = $userservice->getACl();
                 $session = new Zend_Session_Namespace('zend');
                 $session->acl = $acl;
                 $this->_helper->redirector('index', 'index', 'admin');
             }
         }
     }
     $this->view->form = $form;
 }