/**
  *
  * @param sfWebRequest $request
  * @param LoginForm $form
  */
 protected function processLogin(sfWebRequest $request, LoginForm $form)
 {
     $form->bind($request->getParameter('signin'));
     if ($form->isValid()) {
         $values = $form->getValues();
         $this->getUser()->signIn($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
         // Set the tow previous referer to the same value for:
         // 1) redirect to previous user's location
         // 2) avoid redirect loop in signin
         $this->getUser()->setReferer($this->getUser()->getReferer());
         // Redirect to referer
         return $this->redirect($this->getUser()->getReferer());
     }
 }
 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');
     }
 }
 /**
  * Log into the application.
  */
 function loginAction()
 {
     // Set the title for this action.
     $this->view->title = "Login";
     // Wrap the whole thing in a try/catch.
     try {
         // Get a login form.
         $form = new LoginForm();
         // Check to see if this is an invalid form submission.
         if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
             $this->view->loginForm = $form;
             return;
         }
         // Get the form values.
         $values = $form->getValues();
         // Get a new authentication adapter.
         $adapter = new AppAuthAdapter($values['login'], $values['password']);
         // Perform the authentication using the adapter.
         $auth = Zend_Auth::getInstance();
         $result = $auth->authenticate($adapter);
         // Save the identity in the session.
         $session = new Zend_Session_Namespace('Web');
         $session->employee = $auth->getIdentity();
         // Make sure the result is valid.
         if (!$result->isValid()) {
             // Authentication failed.
             $this->view->failedAuthentication = true;
             $this->view->loginForm = $form;
         } else {
             // Authentication succeeded. Determine where to go.
             $this->_helper->redirector('index', 'timesheet', 'user');
             // Save the employee to the view.
             $this->view->employee = $session->employee;
         }
     } catch (Zend_Exception $ex) {
         // Log the error.
         Logger::getLogger()->debug($ex->getMessage());
         // Authentication failed.
         $this->view->failedAuthentication = true;
         $this->view->loginForm = $form;
     }
 }
 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]));
     }
 }
 public function executeLogin($request)
 {
     $form = new LoginForm();
     $form->bind(array('name' => $request->getParameter('name'), 'password' => $request->getParameter('password')));
     if ($form->isValid()) {
         $values = $form->getValues();
         $user = User::getByPassword($values['name'], $values['password']);
         if ($user) {
             $output = '<rsp stat="ok">' . $user->getXML(false, true) . '</rsp>';
         }
     } else {
         $output = '<rsp stat="fail"><err code="1" msg="' . $form->getErrorSchema() . '" /></rsp>';
     }
     $this->output = $output;
     $this->setTemplate('index');
 }