Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login(){
- if($this->request->isPost()){
- try{
- $session = new Zeit_Session('tempLogin');
- $phrase = $this->request->getPost('phrase');
- if(strlen($phrase) > 0 && strlen($session->captcha) > 0 && $phrase == $session->captcha){
- $session->destroy('captcha');
- }else{
- throw new Zeit_Controller_Exception('Por favor intente otra vez');
- }
- unlink(md5(session_id()) . '.png');
- $this->destroySession();
- $idType = $this->request->getPost('tipoIdentificacion');
- $idNumber = $this->request->getPost('identificacion');
- $password = $this->request->getPost('contrasena');
- if($idNumber == ''){
- throw new Zeit_Controller_Exception('Por favor escriba su numero de identificacion');
- }
- $this->logger->info('Verificando si el usuario se encuentra en el sistema...');
- $this->logger->debug('Tipo de identificacion [ ' . $idType . ' ] - Numero de identificacion [ ' . $idNumber . ' ]');
- $userMapper = new Entity_UsuarioMapper();
- $user = $userMapper->findByTypeAndNumberIdentification($idType, $idNumber);
- if(!($user instanceof Entity_Usuario)){
- throw new Zeit_Controller_Exception('El usuario no se encuentra en el sistema');
- }
- if(md5($password) != $user->getContrasena()){
- throw new Zeit_Controller_Exception('La contraseña es invalida');
- }
- $this->logger->info('El usuario si se encontro en el sistema');
- $session = new Zeit_Session('tempLogin');
- $session->loggedUser = $user;
- return 'success';
- }catch(Zeit_Entity_Exception $e){
- $this->logger->debug($e);
- $this->logger->error('Error al ingresar al sistema');
- switch($e->getCode()){
- case 1: $loginForm['error'] = 'no_db_connection'; break;
- case 2: $loginForm['error'] = 'fill_email_and_password'; break;
- case 3: $loginForm['error'] = 'invalid_credentials'; break;
- default: $loginForm['error'] = 'service_unavailable'; break;
- }
- }catch(Zeit_Controller_Exception $e){
- $this->response->addVar('loginForm', $e->getMessage());
- }
- }
- //Set CAPTCHA options
- $imageOptions = array(
- 'font_size' => 24,
- 'font_path' => './',
- //'font_file' => 'Acquaintance.ttf',
- 'font_file' => 'A.C.M.E. Secret Agent Italic.ttf',
- 'text_color' => '#DDFF99',
- 'lines_color' => '#CCEEDD',
- 'background_color' => '#555555'
- );
- //Set CAPTCHA options
- $options = array(
- 'width' => 200,
- 'height' => 80,
- 'output' => 'png',
- 'imageOptions' => $imageOptions
- );
- //Generate a new Text_CAPTCHA object, Image driver
- $c = Text_CAPTCHA::factory('Image');
- $retval = $c->init($options);
- if(PEAR::isError($retval)){
- printf('Error initializing CAPTCHA: %s!', $retval->getMessage());
- exit;
- }
- //Get CAPTCHA secret passphrase
- $session = new Zeit_Session('tempLogin');
- $session->captcha = $c->getPhrase();
- //$_SESSION['phrase'] = $c->getPhrase();
- //Get CAPTCHA image (as PNG)
- $png = $c->getCAPTCHAAsPNG();
- if(PEAR::isError($png)){
- echo 'Error generating CAPTCHA!';
- echo $png->getMessage();
- exit;
- }
- file_put_contents(md5(session_id()) . '.png', $png);
- $this->response->addVar('time', time());
- $this->response->addVar('image', md5(session_id()));
- return 'form';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement