<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Crm\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Ldap\Ldap;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\Ldap as AuthAdapter;    
use Zend\Mvc\Controller\Plugin\Redirect;

class AppController extends AbstractActionController
{   
    public $username, $crmTicketTable;
	protected $status;
    
    public function mainAction()
    {

        $viewModel = new ViewModel();
        return $viewModel; 
        
    }

    //GERAL PAGE
    public function ticketListAction(){      

        $ticketList = $this->getTables('Crm\Model\CustomerTicket')->ticketList($postData, 1, 10);

        $viewModel = new ViewModel(array(
            'ticketList' => $ticketList
        ));

        $viewModel->setTerminal(true);

        return $viewModel;
    }

    public function getTables( $table )
    {
        // adicionar service ModelContato a variavel de classe
        if (!$this->crmTicketTable){
            $this->crmTicketTable = $this->getServiceLocator()->get($table);

            // return vairavel de classe com service ModelContato
            return $this->crmTicketTable;
        }
    }

    public function loginAction()
    {   

        $viewModel = new ViewModel();
        $viewModel->setTerminal(true);
        return $viewModel;

    }

    public function authAction()
    {
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $user = $postData['login'];
        $password = $postData['password'];

        $username = "uid=$user,ou=horizons, ou=people, dc=htt, dc=com";
        $connectLdap = array(
            'host'     => 'ldap://10.100.0.40/',
            'port'     => 389,
            'username' => $username,
            'password' => $password,
            'baseDn'   => 'dc=htt,dc=com'
        );

        $auth = new AuthenticationService();
        $adapter = new AuthAdapter(
            array('server'=>
                $connectLdap
            ),
            $username, 
            $password
        );

        $result = $auth->authenticate($adapter);
        $groups = Array();
        if ( $auth->hasIdentity() ){
            $ldap= new Ldap($connectLdap);            
            
            $result = $ldap->search("(&(objectclass=posixGroup)(memberuid=$user) )"  );
            foreach ($result as $item) {
                $groups[] = $item['cn'][0];
            }

            if (preg_grep('/^(OSS|QEP|NOC SN2)$/', $groups)) {
                $user = $ldap->getEntry($username);
                $auth->getStorage()->write($user);               

                
                $username = $user['cn'][0];
                $ticketList = $this->getTables('Crm\Model\App')->log($username);

                $this->status = 1;
            }
            else{
                $this->status = 2;
                $auth->clearIdentity();
            }

        }
        else{
            $this->status = 0;
            $auth->clearIdentity();
        }

        $viewModel = new ViewModel(array('status' => $this->status) ) ;
        $viewModel->setTerminal(true);
<commit_msg>Permissão de acesso - CRM Atendimento<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Crm\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Ldap\Ldap;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\Ldap as AuthAdapter;    
use Zend\Mvc\Controller\Plugin\Redirect;

class AppController extends AbstractActionController
{   
    public $username, $crmTicketTable;
	protected $status;
    
    public function mainAction()
    {

        $viewModel = new ViewModel();
        return $viewModel; 
        
    }

    //GERAL PAGE
    public function ticketListAction(){      

        $ticketList = $this->getTables('Crm\Model\CustomerTicket')->ticketList($postData, 1, 10);

        $viewModel = new ViewModel(array(
            'ticketList' => $ticketList
        ));

        $viewModel->setTerminal(true);

        return $viewModel;
    }

    public function getTables( $table )
    {
        // adicionar service ModelContato a variavel de classe
        if (!$this->crmTicketTable){
            $this->crmTicketTable = $this->getServiceLocator()->get($table);

            // return vairavel de classe com service ModelContato
            return $this->crmTicketTable;
        }
    }

    public function loginAction()
    {   

        $viewModel = new ViewModel();
        $viewModel->setTerminal(true);
        return $viewModel;

    }

    public function authAction()
    {
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $user = $postData['login'];
        $password = $postData['password'];

        $username = "uid=$user,ou=horizons, ou=people, dc=htt, dc=com";
        $connectLdap = array(
            'host'     => 'ldap://10.100.0.40/',
            'port'     => 389,
            'username' => $username,
            'password' => $password,
            'baseDn'   => 'dc=htt,dc=com'
        );

        $auth = new AuthenticationService();
        $adapter = new AuthAdapter(
            array('server'=>
                $connectLdap
            ),
            $username, 
            $password
        );

        $result = $auth->authenticate($adapter);
        $groups = Array();
        if ( $auth->hasIdentity() ){
            $ldap= new Ldap($connectLdap);            
            
            $result = $ldap->search("(&(objectclass=posixGroup)(memberuid=$user) )"  );

            foreach ($result as $item) {
                $groups[] = $item['cn'][0];
            }

            if (preg_grep('/^(OSS|QEP|NOC SN2|CRM Supervisao)$/', $groups)) {
                $user = $ldap->getEntry($username);
                $auth->getStorage()->write($user);               

                $username = $user['cn'][0];
                $ticketList = $this->getTables('Crm\Model\App')->log($username);

                $this->status = 1;
            }
            else{
                $this->status = 2;
                $auth->clearIdentity();
            }

        }
        else{
            $this->status = 0;
            $auth->clearIdentity();
        }

        $viewModel = new ViewModel(array('status' => $this->status) ) ;
        $viewModel->setTerminal(true);

{'fraction_non_alphanumeric': 0.14088907825592956, 'fraction_numerical': 0.007953415707996023, 'mean_word_length': 1.9195688225538972, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '246249', 'n_tokens_mistral': 2116, 'n_tokens_neox': 1997, 'n_words': 383}