/**
     * KG and PA
     * Log the user in and display the correct homepage
     * This function is called when the login button is pressed.
     * 
     * First it checks the eneered username and password to determine 
     * whether the inputs could be considered valid (long enough username and password,
     * only alpha-numeric characters, etc...)
     * If not, it informs the user and stops executing
     * 
     * Then it queries the matrix user database to determine if the user is actually
     * in the database. If the user was found, it verifies their password with LDAP
     *
     * If the username/password combination was correct, the function queries the user database
     * to determine whether to display the student or faculty page. Otherwise, 
     * take the user back to the login screen and inform them of error.
     */
    
    public function processAction()
    { 
    	$request = $this->getRequest();
    	
        // Check if we have a POST request
        if (!$request->isPost()) {
            return $this->_helper->redirector('login_start');
        }
        
        // Get our form and validate it
        $form = $this->getForm();
        
        
        // Validate username and password for matching criteria
        if (!$form->isValid($request->getPost())) 
        {
            // Redirect to the login page and set error flag	
			$this->_redirect('/index/index/error_flag/TRUE');
        	exit();
        }
        
        //Get username and password
        $username = $form->getValue('username');
        $password = $form->getValue('password');
        
        //check whether user exists in the user table
        $userService = new App_UserService();
        $valid = $userService->ValidUser($username);
        
        
        //If the user exists, validate password with LDAP
        if($valid)
        {
	        $auth = Zend_Auth::getInstance();
	        $authAdapter = new Zend_Auth_Adapter_Ldap(
	                                   array(
	                                           'server' => array(
	                                           'host' => 'ldap.nccnet.noctrl.edu',
	                                           'baseDn' => 'OU=Napvil,O=NCC',
	                                           'bindRequiresDn' => true,
	                                                                   ),
	                                   ), $username, $password
	                           );
	      	$authResult = $auth->authenticate($authAdapter);
	      	if ($authResult->isValid())
	       	{
	       		$valid = TRUE;
	       	} 
	       	else
	       	{
	       		$valid = FALSE;
	       	}
        }
        
        
        if ($valid)
        {
        	$this->view->error_flag = FALSE;
        	$userRole = $userService->GetUserRole($username);
       		
        	if ($userRole == 'U' || $userRole == 'L' || $userRole == 'G')
        	//user is a student
        	{
        		$this->_helper->redirector('index', 'student');
        	}
        	else
        	//user is faculty
        	{
        		$this->_helper->redirector('index', 'faculty');
        	}
        	
        }
        else
        {
        	// Redirect to the login page and set error flag	
			$this->_redirect('/index/index/error_flag/TRUE');
        	exit();
        }
        
    }