Example #1
0
    public function indexAction()
    {
         if($this->_request->isPost()) {
         	if($this->role <= 0)
         	{
	        	$uname = $this->_request->getPost('username');
	        	$password = $this->_request->getPost('password');
         		$auth = App_Auth_Authenticate::getInstance();
         		if(Zend_Auth_Result::SUCCESS == $auth->login($uname, $password))
         		{
         			$this->role = $auth->getUser()->role;
         		} else 
         		{
         			$this->view->errormessage = "Verkeerde gebruikersnaam/wachtwoord combinatie";
         		}
         	}
         }
         if($this->role >= 0)
         {
         	$this->_redirect("/index/view");
         }
         $form = new App_Form_Login();
         $form->setAction($this->url);
         $this->view->form = $form;
    }
 public function indexAction()
 {
     $Form = new App_Form_Login();
     $Request = $this->getRequest();
     if ($Request->isPost()) {
         if ($Form->isValid($Request->getPost())) {
             if ($this->_process($Form->getValues())) {
                 # We are authenticated
                 $this->_helper->redirector('index', 'index');
             }
         }
     }
     $this->view->form = $Form;
 }
 /**
  * Submit 
  */
 public function submitAction()
 {
     $session = Zend_Registry::get('session');
     $options = $this->getInvokeArg('bootstrap')->getOptions();
     $opt = array('custom' => array('timeout' => $options['auth']['timeout']));
     $form = new App_Form_Login($opt);
     $request = $this->getRequest();
     if (!$form->isValid($request->getPost())) {
         if (count($form->getErrors('token')) > 0) {
             return $this->_forward('csrf-forbidden', 'error');
         }
         $this->view->form = $form;
         return $this->render('login');
     }
     $username = $form->getValue('username');
     $password = $form->getValue('password');
     $db = $this->getInvokeArg('bootstrap')->getResource('db');
     $salt = $options['password']['salt'];
     $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', "MD5(CONCAT('{$salt}',?)) AND active=1");
     $authAdapter->setIdentity($username)->setCredential($password);
     $result = $authAdapter->authenticate();
     Zend_Session::regenerateId();
     if (!$result->isValid()) {
         $this->_helper->flashMessenger->addMessage("Authentication error.");
         $this->_redirect('/index/login');
     } else {
         $session->username = $result->getIdentity();
         $users = new App_Model_Users();
         $data = array('last_access' => date('Y-m-d H:i:s'));
         $where = $users->getAdapter()->quoteInto('username = ?', $session->username);
         if (!$users->update($data, $where)) {
             throw new Zend_Exception('Error on update last_access');
         }
         $this->_redirect('/home');
     }
 }
Example #4
0
    /**
     *
     * @todo add openid authentication
     *
     */
    public function loginAction()
    {
        $form = new App_Form_Login();
        if (!empty($_POST) && $form->isValid($_POST)) {
            $username = $form->getValue('username');
            $password = $form->getValue('password');
            //------------------------------------
            // make sure the login form validates
            //------------------------------------
            if ($form->isValid($_POST)) {
                $auth = Zend_Auth::getInstance();
                //------------------------------------------
                // Attempt a standard database login
                //------------------------------------------
                $adapter = new ZendX_Doctrine_Auth_Adapter(Doctrine_Manager::connection(), 'Account', 'username', 'password', 'MD5(?) AND enabled = 1 AND confirmed = 1');
                $adapter->setIdentity($username);
                $adapter->setCredential($password);
                $result = $auth->authenticate($adapter);
                if (!$result->isValid()) {
                    $message = 'The username and password provided does not match our records';
                    $this->_flash->addMessage($message);
                    $form->addError($message);
                } else {
                    $userdata = $adapter->getResultRowObject(null, 'password');
                    //translate the user into an actual doctrine object
                    $accounts = new App_Table_Account();
                    $auth->getStorage()->write($accounts->find($userdata->id));
                    //audit the login
                    $login = new AccountLogin();
                    $login->accountId = $userdata->id;
                    $login->ip = ip2long($_SERVER['REMOTE_ADDR']);
                    $login->save();
                    $this->_flash->addMessage('Welcome back, ' . $result->getIdentity());
                    $this->_redirector->gotoSimple('profile');
                }
            }
        }
        // force users to logout before they can try to login
        if (Zend_Auth::getInstance()->getIdentity() !== null) {
            $this->_flash->addMessage('You are already logged in!  You must log out before you can
				log into a different account.');
            $this->_redirector->gotoSimple('profile');
        }
        $form->setMethod(Zend_Form::METHOD_POST);
        $this->view->form = $form;
    }