<commit_before><?php
/**
 * AuthController
 *  
 */

class AuthController extends Zend_Controller_Action {
	public function init() {
		$this->initView ();
		$this->view->baseUrl = $this->_request->getBaseUrl ();
		//$this->view->baseUrl = Zend_Controller_Front::getParam($route);
	}
	
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
		$this->_redirect ( '/' );
	}
	
	/**
	 * Log in - show the login form or handle a login request
	 * 
	 */
	public function loginAction() {
		$request = $this->getRequest ();
		$form = $this->_getUserLoginForm ();
		
		// check to see if this action has been POST'ed to
		if ($this->getRequest ()->isPost ()) {
			
			// now check to see if the form submitted exists, and
			// if the values passed in are valid for this form
			if ($form->isValid ( $request->getPost () )) {
				
				// collect the data from the user
				

				$f = new Zend_Filter_StripTags ( );
				$email = $f->filter ( $this->_request->getPost ( 'email' ) );
				$password = $f->filter ( $this->_request->getPost ( 'password' ) );
				
				//DDBB validation
				// setup Zend_Auth adapter for a database table
				$dbAdapter = Zend_Registry::get ( 'dbAdapter' );
				$authAdapter = new Zend_Auth_Adapter_DbTable ( $dbAdapter );
				$authAdapter->setTableName ( 'users' );
				$authAdapter->setIdentityColumn ( 'email' );
				$authAdapter->setCredentialColumn ( 'password' );
				// Set the input credential values to authenticate against
				$authAdapter->setIdentity ( $email );
				$authAdapter->setCredential ( md5 ( trim($password) ) ); //trim whitespaces from copy&pasting the pass from email
				
				// do the authentication
				$auth = Zend_Auth::getInstance ();
				
				//check first if the user is activated (by confirmed email)
				$select = $authAdapter->getDbSelect ();
				$select->where ( 'active > 0' );
				
				$result = $authAdapter->authenticate ();
				if ($result->isValid ()) {
					// success: store database row to auth's storage
					// system. (Not the password though!)
					$data = $authAdapter->getResultRowObject ( null, 'password' );
					$auth->getStorage ()->write ( $data );
					
					$this->_helper->_flashMessenger->addMessage ( $this->view->translate ( 'You are now logged in, ' ) . $username );
					
					
					//check the redir value if setted
					$aNamespace = new Zend_Session_Namespace('Nolotiro');
					$redir = $aNamespace->redir;
					
					if ($redir !== null){
						
					  $aNamespace->redir = null; //reset redir value
					  $this->_redirect ( $redir );
					
					}else {
					
					  //if redir empty goto main home ads
					  $this->_redirect ( '/' );
					}
					
					<commit_msg>issue #1 fixed<commit_after><?php
/**
 * AuthController
 *  
 */

class AuthController extends Zend_Controller_Action {
	public function init() {

                //parent::init ();
		$this->view->baseUrl = Zend_Controller_Front::getParam ( $route );

		$locale = Zend_Registry::get ( "Zend_Locale" );
		$this->lang = $locale->getLanguage ();

                $aNamespace = new Zend_Session_Namespace('Nolotiro');
		$this->location = $aNamespace->location;

	}
	
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
		$this->_redirect ( '/' );
	}
	
	/**
	 * Log in - show the login form or handle a login request
	 * 
	 */
	public function loginAction() {
		$request = $this->getRequest ();
		$form = $this->_getUserLoginForm ();
		
		// check to see if this action has been POST'ed to
		if ($this->getRequest ()->isPost ()) {
			
			// now check to see if the form submitted exists, and
			// if the values passed in are valid for this form
			if ($form->isValid ( $request->getPost () )) {
				
				// collect the data from the user
				

				$f = new Zend_Filter_StripTags ( );
				$email = $f->filter ( $this->_request->getPost ( 'email' ) );
				$password = $f->filter ( $this->_request->getPost ( 'password' ) );
				
				//DDBB validation
				// setup Zend_Auth adapter for a database table
				$dbAdapter = Zend_Registry::get ( 'dbAdapter' );
				$authAdapter = new Zend_Auth_Adapter_DbTable ( $dbAdapter );
				$authAdapter->setTableName ( 'users' );
				$authAdapter->setIdentityColumn ( 'email' );
				$authAdapter->setCredentialColumn ( 'password' );
				// Set the input credential values to authenticate against
				$authAdapter->setIdentity ( $email );
				$authAdapter->setCredential ( md5 ( trim($password) ) ); //trim whitespaces from copy&pasting the pass from email
				
				// do the authentication
				$auth = Zend_Auth::getInstance ();
				
				//check first if the user is activated (by confirmed email)
				$select = $authAdapter->getDbSelect ();
				$select->where ( 'active > 0' );
                                //check if the user is not locked (spammers, bad users, etc)
                                $select->where ( 'locked = 0' );
				
				$result = $authAdapter->authenticate ();
				if ($result->isValid ()) {
					// success: store database row to auth's storage
					// system. (Not the password though!)
					$data = $authAdapter->getResultRowObject ( null, 'password' );
					$auth->getStorage ()->write ( $data );
					
					$this->_helper->_flashMessenger->addMessage ( $this->view->translate ( 'You are now logged in, ' ) . $username );
					
					
					//check the redir value if setted
					$aNamespace = new Zend_Session_Namespace('Nolotiro');
					$redir = $aNamespace->redir;
					
					if ($redir !== null){
						
					  $aNamespace->redir = null; //reset redir value
					  $this->_redirect ( $redir );
					
					}else {
					
					  //if redir empty goto main home ads and set the welcome logged in message
					 $this->_redirect ( '/'.$this->lang.'/ad/list/woeid/'.$this->location.'/ad_type/give' );
					}
					
					
{'fraction_non_alphanumeric': 0.14344899016053858, 'fraction_numerical': 0.0010357327809425167, 'mean_word_length': 2.598757763975155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '812401', 'n_tokens_mistral': 2153, 'n_tokens_neox': 1665, 'n_words': 473}