/** * Enter description here... * * @param Zend_Controller_Request_Abstract $request */ public function preDispatch(Zend_Controller_Request_Abstract $request) { // ziskame instanci redirector helperu, ktery ma starosti presmerovani $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector'); $auth = Zend_Auth::getInstance(); // Stav o autentifikaci uzivatele (prihlaseni) se musi nekde udrzovat, vychozi zpusob je session // u session lze nastavit namespace, vychozi je Zend_Auth //$auth->setStorage(new Zend_Auth_Storage_Session('My_Auth')); if ($request->getParam('logout')) { // detekovano odhlaseni $auth->clearIdentity(); // kvuli bezpecnosti provedeme presmerovani $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController); } if ($request->getPost('login')) { $db = Zend_Db_Table::getDefaultAdapter(); // Vytvarime instance adapteru pro autentifikaci // nastavime parametry podle naseho nazvu tabulky a sloupcu // treatment obsahuje pripadne pouzitou hashovaci funkci pro heslo, napr. SHA1 $adapter = new Zend_Auth_Adapter_DbTable($db, $this->tableName, $this->identityColumn, $this->credentialColumn, $this->treatment); $form = new LoginForm(); // validace se nezdari, napr. prazdny formular if (!$form->isValid($request->getPost())) { // FlashMessenger slouzi k uchovani zprav v session $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $flash->clearMessages(); $flash->addMessage('Please fill the login form'); $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController, null, array('login-failed' => 1)); } $username = $form->getValue($this->loginField); $password = $form->getValue($this->passwordField); // přidáme salt $password = "******" . $password; // jmeno a heslo predame adapteru $adapter->setIdentity($username); $adapter->setCredential($password); // obecny proces autentifikace s libovolnym adapterem $result = $auth->authenticate($adapter); if ($auth->hasIdentity()) { // Uzivatel byl uspesne overen a je prihlasen // identity obsahuje v nasem pripade ID uzivatele z databaze $identity = $auth->getIdentity(); // presmerujeme $redirector->gotoSimpleAndExit($this->successAction, $this->successController); } else { // autentifikace byla neuspesna // FlashMessenger slouzi k uchovani zprav v session $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); // vlozime do session rovnou chybove hlasky, ktere pak predame do view foreach ($result->getMessages() as $msg) { $flash->addMessage($msg); } $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController, null, array('login-failed' => 1)); } } }
public function loginAction() { $request = $this->getRequest(); $config = Zend_Registry::get('config'); // Check if we have a POST request if (!$request->isPost()) { $this->_helper->redirector('index', 'index'); } $lang = $this->getRequest()->getPost('lang'); if (isset($lang) && $lang != null) { $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; } // Get our form and validate it $form = new LoginForm(); if (!$form->isValid($request->getPost())) { // Invalid entries $this->_flashMessenger->addMessage('Email or Password is required and its length should between 6 and 20'); $this->view->form = $form; $this->_helper->redirector('loginfailed', 'index'); } // Get our authentication adapter and check credentials $adapter = new LoginAuthAdapter($form->getValue('email'), $form->getValue('password')); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if ($result->isValid()) { // We're authenticated! Redirect to the home page $db = Zend_Registry::get('db'); $consumer_id = $db->fetchOne("SELECT id FROM consumer WHERE email = :temp or login_phone = :temp and state='ACTIVE'", array('temp' => $form->getValue('email'))); $consumerModel = new Consumer(); $consumer = $consumerModel->find($consumer_id)->current(); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = $consumer; $authNamespace->role = 'consumer'; //log $logModel = new Log(); $logId = $logModel->insert(array('consumer_id' => $consumer->id, 'date' => date("Y-m-d H:i:s"), 'event' => 'LOGIN')); $url = $form->getValue('url'); if (isset($url) && !empty($url)) { $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_redirector->gotoUrl($url); } else { $this->_helper->redirector('index', 'home'); } } else { // Invalid credentials $this->_flashMessenger->addMessage('Invalid credentials provided'); $this->view->form = $form; $this->_helper->redirector('loginfailed', 'index'); } }
public function loginAction() { $request = $this->getRequest(); // Check if we have a POST request if (!$request->isPost()) { $this->_helper->redirector('index', 'admin'); } // Get our form and validate it $form = new LoginForm(); if (!$form->isValid($request->getPost())) { // Invalid entries $this->view->form = $form; $this->_helper->redirector('index', 'admin'); // re-render the login form } // Get our authentication adapter and check credentials $adapter = $this->getAuthAdapter($form->getValues()); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if (!$result->isValid()) { // Invalid credentials $form->setDescription('Invalid credentials provided'); $this->view->form = $form; $this->_helper->redirector('index', 'admin'); // re-render the login form } $db = Zend_Registry::get('db'); $admin_id = $db->fetchOne("SELECT id FROM admin WHERE email = :temp", array('temp' => $auth->getIdentity())); $adminModel = new Admin(); $admin = $adminModel->find($admin_id)->current(); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); //2011-04-08 ham.bao separate the sessions with admin //$authNamespace->user = $admin; $authNamespace->admin = $admin; //2011-04-08 ham.bao separate the sessions with admin $authNamespace->role = 'administrator'; // We're authenticated! Redirect to the home page $url = $form->getValue('url'); if (isset($url) && !empty($url)) { $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_redirector->gotoUrl($url); } else { $this->_helper->redirector('adminindex', 'campaign'); } }
public function loginAction() { $request = $this->getRequest(); // Check if we have a POST request if (!$request->isPost()) { $this->_helper->redirector('index', 'client'); } // Get our form and validate it $form = new LoginForm(); if (!$form->isValid($request->getPost())) { // Invalid entries $this->view->form = $form; $this->_flashMessenger->addMessage("Email or password is incorrect."); $this->_helper->redirector('index', 'client'); // re-render the login form } // Get our authentication adapter and check credentials $adapter = $this->getAuthAdapter($form->getValues()); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if (!$result->isValid()) { // Invalid credentials $form->setDescription('Invalid credentials provided'); $this->view->form = $form; $this->_flashMessenger->addMessage("Email or password is incorrect."); $this->_helper->redirector('index', 'client'); // re-render the login form } $db = Zend_Registry::get('db'); $client_id = $db->fetchOne("SELECT id FROM client WHERE email = :temp", array('temp' => $auth->getIdentity())); $clientModel = new Client(); $client = $clientModel->find($client_id)->current(); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); //2011-04-08 ham.bao separate the sessions with client $authNamespace->client = $client; // get accessible campaign list $clientCampaginSelect = $db->select(); $clientCampaginSelect->from('client_campaign', 'campaign_id')->join('campaign', 'client_campaign.campaign_id = campaign.id', array('name'))->where('client_campaign.client_id = ?', $client_id)->order('campaign.id desc'); $clientCampaign = $db->fetchAll($clientCampaginSelect); $campaignlist = array(); foreach ($clientCampaign as $temp) { $campaignlist[$temp['campaign_id']] = array($temp['campaign_id'], $temp['name']); } $clientCampaignListNamespace = new Zend_Session_Namespace('ClientCampaignList'); if ($clientCampaignListNamespace->list == null) { $clientCampaignListNamespace->list = $campaignlist; } // We're authenticated! Redirect to the home page $url = $form->getValue('url'); //get unviewed message count save it to session $clientMessageNamespace = new Zend_Session_Namespace('ClientMessage'); //$db = Zend_Registry::get('db'); $messageCount = $db->fetchOne("SELECT count(*) FROM client_message cm WHERE cm.to_type='Client' and cm.to=:clientId and state='NEW'", array('clientId' => $client_id)); if ($messageCount > 0) { $attrName = "count_" . $client_id; $clientMessageNamespace->{$attrName} = $messageCount; } if (isset($url) && !empty($url)) { $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_redirector->gotoUrl($url); } else { $campaignIdArray = array_keys($campaignlist); $this->_helper->redirector('clientcloudtag', 'dashboard', null, array('id' => $campaignIdArray[0])); } }
/** * Enter description here... * * @param Zend_Controller_Request_Abstract $request */ public function preDispatch(Zend_Controller_Request_Abstract $request) { // ziskame instanci redirector helperu, ktery ma starosti presmerovani $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector'); $auth = Zend_Auth::getInstance(); // Stav o autentifikaci uzivatele (prihlaseni) se musi nekde udrzovat, vychozi zpusob je session // u session lze nastavit namespace, vychozi je Zend_Auth //$auth->setStorage(new Zend_Auth_Storage_Session('My_Auth')); if ($request->getParam('logout')) { // detekovano odhlaseni $auth->clearIdentity(); // kvuli bezpecnosti provedeme presmerovani $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController); } if ($request->getPost('login')) { $db = Zend_Db_Table::getDefaultAdapter(); // Vytvarime instance adapteru pro autentifikaci // nastavime parametry podle naseho nazvu tabulky a sloupcu // treatment obsahuje pripadne pouzitou hashovaci funkci pro heslo, napr. SHA1 $adapter = new Zend_Auth_Adapter_DbTable($db, $this->tableName, $this->identityColumn, $this->credentialColumn, $this->treatment); $form = new LoginForm(); // validace se nezdari, napr. prazdny formular if (!$form->isValid($request->getPost())) { // FlashMessenger slouzi k uchovani zprav v session $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $flash->clearMessages(); $flash->setNamespace("error")->addMessage("Please fill the login form!"); $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController, null, array('login-failed' => 1)); } $username = $form->getValue($this->loginField); $password = $form->getValue($this->passwordField); // jmeno a heslo predame adapteru $adapter->setIdentity($username); $user = My_Model::get('Users')->fetchRow(array("username = ?" => $username)); if ($user == null) { $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController, null, array('login-failed' => 1)); } $salt = $user->getSalt(); $adapter->setCredential($password . $salt); // obecny proces autentifikace s libovolnym adapterem $result = $auth->authenticate($adapter); if ($auth->hasIdentity()) { // Uzivatel byl uspesne overen a je prihlasen $identity = $auth->getIdentity(); // identity obsahuje v nasem pripade ID uzivatele z databaze // muzeme napr. ulozit IP adresu, cas posledniho prihlaseni atd. $db->update($this->tableName, array('lognum' => new Zend_Db_Expr('lognum + 1'), 'ip' => $request->getServer('REMOTE_ADDR'), 'last_login' => new Zend_Db_Expr('NOW()'), 'browser' => $request->getServer('HTTP_USER_AGENT')), $this->identityColumn . " = '{$identity}'"); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $flash->clearMessages(); $flash->setNamespace("success")->addMessage("Success! You are logged in!"); // presmerujeme $redirector->gotoSimpleAndExit($this->successAction, $this->successController); } else { // autentifikace byla neuspesna // FlashMessenger slouzi k uchovani zprav v session $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $flash->clearMessages(); // vlozime do session rovnou chybove hlasky, ktere pak predame do view foreach ($result->getMessages() as $msg) { $flash->setNamespace("error")->addMessage("Login failed, please try again!"); } /* // nicmene muzeme je nastavit podle konkretniho chyboveho kodu if ($result == Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID) { // neplatne heslo } else if ($result == Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS) { // nalezeno vice uzivatelskych identit } else if ($result == Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND) { // identita uzivatele nenalezena } * */ $redirector->gotoSimpleAndExit($this->failedAction, $this->failedController, null, array('login-failed' => 1)); } } }
/** * login action, Allow the User to connect * @author EL GUENNUNI Sohaib s.elguennuni@gmail.com * @param <empty> * @return <empty> */ public function loginAction() { if (BaseUser::isLogged()) { $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'wall', 'action' => 'index'), 'default', true)); } $this->title = 'Login'; $form = new LoginForm(); if ($this->getRequest()->isPost()) { if ($registration = $this->getRequest()->getParam('inscription', false)) { $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'user', 'action' => 'add'), 'default', true)); } if ($form->isValid($this->getRequest()->getPost())) { if ($this->_userModel->login($form->getValue('username'), $form->getValue('password'))) { $member = App_Utilities::setMember_Registry(); if ($member->validate == 1) { $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'wall', 'action' => 'index'), 'default', true)); } else { Zend_Auth::getInstance()->clearIdentity(); Zend_Session::destroy(); $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'user', 'action' => 'login'), 'default', true)); } } } else { $this->_authentification->addFailedLogin(); } $this->view->error = TRUE; } $this->view->form = $form; }
/** * Allows users to log into the application * * @access public * @return void */ public function loginAction() { $this->title = 'Login'; // use the login layout $this->_helper->layout()->setLayout('login'); $form = new LoginForm(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $userModel = new BackofficeUser(); if ($userModel->login($form->getValue('username'), $form->getValue('password'))) { $session = new Zend_Session_Namespace('App.Backoffice.Controller'); $request = unserialize($session->request); if (!empty($request)) { $previousUri = $request->getRequestUri(); $this->_redirect($previousUri); } else { $this->_redirect('/profile/'); } } } $this->view->error = TRUE; } $this->view->form = $form; }
/** * Login process */ public function executeLogin(sfWebRequest $r) { // If we've posted the form if ($r->isMethod('post')) { // Launching form $login = new LoginForm(); // Binding fields to validators $login->bind($r->getParameter($login->getName())); // Doing a little sleep to prevent automatic bruteforce sleep(1); // If form is valid if ($login->isValid()) { // Fetching account for this user $q = Doctrine::getTable("Users")->findOneByUsername($login->getValue("username")); // Setting cookies for auto-login $this->getResponse()->setCookie("uid", $q->getId(), time() + 365 * 3600 * 24); $this->getResponse()->setCookie("pwd", $q->getCookiesHash(), time() + 365 * 3600 * 24); // Informing user $this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Happy to see you %s% !", array("%s%" => $q->getUsername()))); if ($r->isXmlHttpRequest()) { $this->getResponse()->setStatusCode(202); return $this->renderText(""); } } else { $c = (string) $login->getErrorSchema(); preg_match_all('#(.+) \\[(.+)\\]#U', $c, $m); $m[1] = array_map('trim', $m[1]); die(json_encode($m, JSON_FORCE_OBJECT)); } } // Redirect to homepage $this->redirect("@homepage"); }