Advertisement
Guest User

Untitled

a guest
May 1st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. public function login(){
  2.             if($this->request->isPost()){
  3.                 try{
  4.                     $session = new Zeit_Session('tempLogin');
  5.                     $phrase = $this->request->getPost('phrase');
  6.                    
  7.                     if(strlen($phrase) > 0 && strlen($session->captcha) > 0 && $phrase == $session->captcha){
  8.                         $session->destroy('captcha');
  9.                     }else{
  10.                         throw new Zeit_Controller_Exception('Por favor intente otra vez');
  11.                     }
  12.                    
  13.                     unlink(md5(session_id()) . '.png');
  14.                    
  15.                     $this->destroySession();
  16.                    
  17.                     $idType = $this->request->getPost('tipoIdentificacion');
  18.                     $idNumber = $this->request->getPost('identificacion');
  19.                     $password = $this->request->getPost('contrasena');
  20.                    
  21.                     if($idNumber == ''){
  22.                         throw new Zeit_Controller_Exception('Por favor escriba su numero de identificacion');
  23.                     }
  24.                    
  25.                     $this->logger->info('Verificando si el usuario se encuentra en el sistema...');
  26.                     $this->logger->debug('Tipo de identificacion [ ' . $idType . ' ] - Numero de identificacion [ ' . $idNumber . ' ]');
  27.                    
  28.                     $userMapper = new Entity_UsuarioMapper();
  29.                     $user = $userMapper->findByTypeAndNumberIdentification($idType, $idNumber);
  30.                    
  31.                     if(!($user instanceof Entity_Usuario)){
  32.                         throw new Zeit_Controller_Exception('El usuario no se encuentra en el sistema');
  33.                     }
  34.                    
  35.                     if(md5($password) != $user->getContrasena()){
  36.                         throw new Zeit_Controller_Exception('La contraseña es invalida');
  37.                     }
  38.                    
  39.                     $this->logger->info('El usuario si se encontro en el sistema');
  40.                    
  41.                     $session = new Zeit_Session('tempLogin');
  42.                     $session->loggedUser = $user;
  43.                    
  44.                     return 'success';
  45.                 }catch(Zeit_Entity_Exception $e){
  46.                     $this->logger->debug($e);
  47.                     $this->logger->error('Error al ingresar al sistema');
  48.                     switch($e->getCode()){
  49.                         case 1: $loginForm['error'] = 'no_db_connection'; break;
  50.                         case 2: $loginForm['error'] = 'fill_email_and_password'; break;
  51.                         case 3: $loginForm['error'] = 'invalid_credentials'; break;
  52.                         default: $loginForm['error'] = 'service_unavailable'; break;
  53.                     }
  54.                 }catch(Zeit_Controller_Exception $e){
  55.                     $this->response->addVar('loginForm', $e->getMessage());
  56.                 }
  57.             }
  58.            
  59.             //Set CAPTCHA options
  60.             $imageOptions = array(
  61.                 'font_size' => 24,
  62.                 'font_path' => './',
  63.                 //'font_file' => 'Acquaintance.ttf',
  64.                 'font_file' => 'A.C.M.E. Secret Agent Italic.ttf',
  65.                 'text_color' => '#DDFF99',
  66.                 'lines_color' => '#CCEEDD',
  67.                 'background_color' => '#555555'
  68.             );
  69.            
  70.             //Set CAPTCHA options
  71.             $options = array(
  72.                 'width' => 200,
  73.                 'height' => 80,
  74.                 'output' => 'png',
  75.                 'imageOptions' => $imageOptions
  76.             );
  77.            
  78.             //Generate a new Text_CAPTCHA object, Image driver
  79.             $c = Text_CAPTCHA::factory('Image');
  80.             $retval = $c->init($options);
  81.             if(PEAR::isError($retval)){
  82.                 printf('Error initializing CAPTCHA: %s!', $retval->getMessage());
  83.                 exit;
  84.             }
  85.            
  86.             //Get CAPTCHA secret passphrase
  87.             $session = new Zeit_Session('tempLogin');
  88.             $session->captcha = $c->getPhrase();
  89.             //$_SESSION['phrase'] = $c->getPhrase();
  90.            
  91.             //Get CAPTCHA image (as PNG)
  92.             $png = $c->getCAPTCHAAsPNG();
  93.             if(PEAR::isError($png)){
  94.                 echo 'Error generating CAPTCHA!';
  95.                 echo $png->getMessage();
  96.                 exit;
  97.             }
  98.             file_put_contents(md5(session_id()) . '.png', $png);
  99.            
  100.             $this->response->addVar('time', time());
  101.             $this->response->addVar('image', md5(session_id()));
  102.            
  103.             return 'form';
  104.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement