* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace UBV\AutenticacionBundle\Controller; use FOS\UserBundle\Controller\RegistrationController as BaseController; use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseUserEvent; use FOS\UserBundle\FOSUserEvents; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use UBV\SurUbvbundle\Entity\Aspirante; use UBV\SurUbvBundle\Entity\EstudianteDocumento; use UBV\SurUbvBundle\Entity\Deposito; use UBV\SurUbvbundle\Entity\PersonaNacionalidad; use UBV\SurUbvBundle\Entity\PersonaCorreo; use UBV\SurUbvBundle\Entity\PersonaTelefono; use UBV\SurUbvBundle\Entity\PersonalAdministrativo; use UBV\AutenticacionBundle\Form\Type\RegistrationAspirantePreGradoType; use UBV\AutenticacionBundle\Form\Type\RegistrationAspirantePostGradoType; use UBV\AutenticacionBundle\Form\Type\RegistrationPersonaType; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use FOS\UserBundle\Event\FilterUserResponseEvent; class RegistrationController extends BaseController { public function registerPersonalUbvAction(Request $request) { //die($request->attributes->get('cedula')); //die(dump($request->attributes->get('mykey'))); /** @var $formFactory FactoryInterface */ $formFactory = $this->get('fos_user.registration.form.factory'); /** @var $userManager UserManagerInterface */ $userManager = $this->get('fos_user.user_manager'); /** @var $dispatcher EventDispatcherInterface */ $dispatcher = $this->get('event_dispatcher'); $user = $userManager->createUser(); $user->setEnabled(true); $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event); if (null !== $event->getResponse()) { return $event->getResponse(); } $form = $this->createForm( new RegistrationPersonaType()); //$aspirante = new Aspirante(); $nacionalidad = new PersonaNacionalidad(); $telefonoMovil = new PersonaTelefono(); $personalAdministrativo = new PersonalAdministrativo(); //$documento = new EstudianteDocumento(); $personaCorreo = new PersonaCorreo(); $user->getPersonaNacionalidads()->add($nacionalidad); $user->getPersonaTelefonos()->add($telefonoMovil); //$user->getAspirantes()->add($aspirante); $user->getPersonalAdministrativos()->add($personalAdministrativo); $nacionalidad->setPersona($user); $nacionalidad->setEstatus(true); $personaCorreo->setPersona($user); $telefonoMovil->setPersona($user); $personalAdministrativo->setPersona($user); //$user->getEstudianteDocumentos()->add($documento); $user->getPersonaCorreos()->add($personaCorreo); $user->setEmail('prueba@ubv.edu.ve'); $user->setUserName('Prueba'); $form->setData($user); $form->handleRequest($request); if ($form->isSubmitted()) { if ($form->isValid()) { $datosForm = $request->get('app_user_persona_registration'); //die(dump($datosForm["personaCorreos"][0]["correo"])); $cuentaInstitucional = $this->generarCorreoInstitucionalAspiranteAction($form->getData()->getPrimerNombre(), $form->getData()->getSegundoNombre(), $form->getData()->getPrimerApellido(), $form->getData()->getSegundoApellido()); //die(dump($cuentaInstitucional)); $user->setUsername($cuentaInstitucional); $user->setEmail($datosForm["personaCorreos"][0]["correo"]); $user->setUsernameCanonical($cuentaInstitucional); $user->setEmailCanonical($datosForm["personaCorreos"][0]["correo"]); //$correoPersonal = $cuentaInstitucional.'@surubv.edu.ve'; //die(dump($user)); $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event); $userManager->updateUser($user); $url = $this->generateUrl('persona_index'); $response = new RedirectResponse($url); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); return $response; } $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event); if (null !== $response = $event->getResponse()) { return $response; } } return $this->render(':persona:new.html.twig', array( 'form' => $form->createView(), )); } public function registerAction(Request $request) { //die(var_dump($request->getMethod())); if($request->getMethod() == "GET" ){ throw new AccessDeniedException('This user does not have access to this section.'); }else { $em = $this->getDoctrine()->getManager(); $session = $request->getSession(); if(is_null($request->get('registro_aspirante'))){ $datosFormulario = $session->get('datosForm'); //die(var_dump($datosFormulario)); //$request->attributes->set('datosFormulario', $datosFormulario); }else{ $session->set('datosForm', $request->get('registro_aspirante')); $datosFormulario = $request->get('registro_aspirante'); } $objetoProgramaNivel = $em->getRepository('UBVSurUbvBundle:ProgramaNivel')->findOneById($datosFormulario["programaNivel"]); $accesoRegistro = $this->validacionTipoAspiranteAction($datosFormulario); //die(dump($accesoRegistro)); /** @var $formFactory FactoryInterface */ $formFactory = $this->get('fos_user.registration.form.factory'); /** @var $userManager UserManagerInterface */ $userManager = $this->get('fos_user.user_manager'); /** @var $dispatcher EventDispatcherInterface */ $dispatcher = $this->get('event_dispatcher'); if($accesoRegistro["tipoValidacion"] == "Aspirante" || $accesoRegistro["tipoValidacion"] == "Estudiante"){ return $this->registroAspiranteDenegadoAction($accesoRegistro["tipoValidacion"], $accesoRegistro["datos"]); }else{ if($accesoRegistro["tipoValidacion"] == "Persona"){ $session->set('personaId', $accesoRegistro["datos"]["IdPersona"]); $session->set('programaNivel', $datosFormulario["programaNivel"]); if($objetoProgramaNivel->getDescripcion() == 'Pre-Grado'){ //$aspirante = new Aspirante(); //$documento = new EstudianteDocumento(); // $nacionalidad = new PersonaNacionalidad(); // //$persona = $em->getRepository("UBVSurUbvBundle:Persona")->findOneById($accesoRegistro["datos"]["IdPersona"]); // $personaNacionalidad = $em->getRepository("UBVSurUbvBundle:PersonaNacionalidad")->findOneByPersona($accesoRegistro["datos"]["IdPersona"]); // //$persona->getAspirantes()->add($aspirante); // //$documentoidentidad = $em->getRepository('UBVSurUbvBundle:DocumentoidentidadTipo')->findOneById($accesoRegistro["datos"]["TipoDocIdent"]); // //$persona->getPersonaNacionalidads()->add($nacionalidad); //$persona->getEstudianteDocumentos()->add($documento); // // //$nacionalidad->setDocumentoIdentidadTipo($documentoidentidad); // //$nacionalidad->setIdentificacion($accesoRegistro["datos"]["NumIdentificacion"]); return $this->forward('UBVSurUbvBundle:Aspirante:new'); //$form = $this->createForm(RegistrationAspirantePreGradoType::class); //$formFactory = $this->get('fos_user.registration.form.factory')->createForm(new RegistrationAspirantePreGradoType(),$persona); //die(var_dump($documentoidentidad)); //$form->setData($persona); }elseif($objetoProgramaNivel->getDescripcion() == 'Post-Grado'){ $persona = $em->getRepository("UBVSurUbvBundle:Persona")->findOneById($accesoRegistro["datos"]["IdPersona"]); return $this->forward('UBVSurUbvBundle:Aspirante:new'); }else{ die(var_dump("Opcion Invalida")); } }elseif($accesoRegistro["tipoValidacion"] == "Candidato"){ //die(dump($accesoRegistro)); //********************************************************************************************************************************// $aspiranteTipo = $accesoRegistro["datos"]->getAspiranteTipo(); $periodoAcademicoActivo= $accesoRegistro["datos"]->getPeriodoAcademico(); $estatusAspirante = $accesoRegistro["datos"]->getAspiranteEstatus(); $correoTipo = $accesoRegistro["datos"]->getCorreoTipo(); $tipoDocumentoIdentificacion = $accesoRegistro["datos"]->getDocumentoIdentidadTipo(); $numIdentificacion = intval($accesoRegistro["datos"]->getIdentificacion()); $primerNombre = $accesoRegistro["datos"]->getPrimerNombre(); $segundoNombre = $accesoRegistro["datos"]->getSegundoNombre(); $primerApellido = $accesoRegistro["datos"]->getPrimerApellido(); $segundoApellido = $accesoRegistro["datos"]->getSegundoApellido(); $email = $accesoRegistro["datos"]->getCorreo(); $telefono = $accesoRegistro["datos"]->getTelefono(); $telefonoCodigoArea = $accesoRegistro["datos"]->getTelefonoCodigoArea(); $aldea = $accesoRegistro["datos"]->getAldea(); $programa = $accesoRegistro["datos"]->getPrograma(); $promedioNota = $accesoRegistro["datos"]->getPromedioNota(); $genero = $accesoRegistro["datos"]->getGenero(); $estadoCivil = $accesoRegistro["datos"]->getEstadoCivil(); $fechaNacimiento = $accesoRegistro["datos"]->getfechaNacimiento(); $anoGrado = $accesoRegistro["datos"]->getAnoGrado(); $codigoOpsu = $accesoRegistro["datos"]->getIdOpsu(); $trabaja = $accesoRegistro["datos"]->getTrabaja(); $etnia = $accesoRegistro["datos"]->getEtnia(); $discapacidad = $accesoRegistro["datos"]->getDiscapacidad(); //********************************************************************************************************************************// //$aspiranteTipo = $em->getRepository('UBVSurUbvBundle:AspiranteTipo')->findOneById(4); //$periodoAcademicoActivo= $em->getRepository('UBVSurUbvBundle:PeriodoAcademico')->findObjetoPeriodoAcademicoByEstatus(); //$estatusAspirante = $em->getRepository('UBVSurUbvBundle:AspiranteEstatus')->findOneById(2); //$correoTipo = $em->getRepository('UBVSurUbvBundle:CorreoTipo')->findOneByDescripcion("Personal"); //$tipoDocumentoIdentificacion = $em->getRepository('UBVSurUbvBundle:DocumentoIdentidadTipo')->findOneById($datosFormulario["tipoDocumentoIdentificacion"]); //$numIdentificacion = intval($datosFormulario["identificacion"]); $nivelPrograma = $datosFormulario["programaNivel"]; //$primerNombre = $datosFormulario["primerNombre"]; //$segundoNombre = $datosFormulario["segundoNombre"]; //$primerApellido = $datosFormulario["primerApellido"]; //$segundoApellido = $datosFormulario["segundoApellido"]; $grupo = "Aspirante"; $gruposAsignar = $em->getRepository('UBVSurUbvBundle:Grupo')->findObjetoGrupoByDescripcion($grupo); $user = $userManager->createUser(); $user->setEnabled(false); $user->setPrimerNombre($primerNombre); $user->setSegundoNombre($segundoNombre); $user->setPrimerApellido($primerApellido); $user->setSegundoApellido($segundoApellido); $user->setGenero($genero); $user->setEstadoCivil($estadoCivil); $user->setFechaNacimiento($fechaNacimiento); $cuentaInstitucional = $this->generarCorreoInstitucionalAspiranteAction($primerNombre, $segundoNombre, $primerApellido, $segundoApellido); $user->setUsername($cuentaInstitucional.'_ubv'); $correoPersonal = $cuentaInstitucional.'@surubv.edu.ve'; $user->setEmail($correoPersonal); $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if($objetoProgramaNivel->getDescripcion() == 'Pre-Grado'){ $form = $formFactory->createForm(); //$form->add('genero',null,array('disabled'=>true)); $template = 'FOSUserBundle:Registration:registerCandidato.html.twig'; }elseif($objetoProgramaNivel->getDescripcion() == 'Post-Grado'){ $form = $this->createForm(RegistrationAspirantePostGradoType::class); $template = 'FOSUserBundle:Registration:register_postgrado.html.twig'; $deposito = new Deposito(); $user->getDepositos()->add($deposito); $deposito->setPersona($user); //die(var_dump("En postgrado")); }else{ die(var_dump("Opcion Invalida")); } //$form = $formFactory->createForm(); //$datos_aspirante = $request->get('registro_aspirante'); //$tipoDoc = $em->getRepository("UBVSurUbvBundle:DocumentoIdentidadTipo")->findOneById($datos_aspirante["tipoDocumentoIdentificacion"]); $aspirante = new Aspirante(); $nacionalidad = new PersonaNacionalidad(); $telefonoMovil = new PersonaTelefono(); $telefonoMovil->setTelefono($telefono); $telefonoMovil->setTelefonoCodigoArea($telefonoCodigoArea); //$documento = new EstudianteDocumento(); $personaCorreo = new PersonaCorreo(); $personaCorreo->setCorreo($email); $personaCorreo->setCorreoTipo($correoTipo); $aspirante->setPeriodoAsignado($periodoAcademicoActivo); $aspirante->setAspiranteTipo($aspiranteTipo); $aspirante->setAnoGrado($anoGrado); $aspirante->setCodigoOpsu($codigoOpsu); $aspirante->setTrabajo($trabaja); //$nacionalidad->setDocumentoIdentidadTipo($tipoDocumentoIdentificacion); $nacionalidad->setIdentificacion($numIdentificacion); //die((var_dump($session->get('datosFormulario')))); $nacionalidad->setDocumentoIdentidadTipo($tipoDocumentoIdentificacion); $user->getAspirantes()->add($aspirante); $user->getPersonaNacionalidads()->add($nacionalidad); $user->getPersonaTelefonos()->add($telefonoMovil); //$user->getEstudianteDocumentos()->add($documento); $user->getPersonaCorreos()->add($personaCorreo); $aspirante->setPersona($user); $aspirante->setPrograma($programa); $aspirante->setAldea($aldea); $aspirante->setPromedioNota($promedioNota); $nacionalidad->setPersona($user); $nacionalidad->setEstatus(true); $personaCorreo->setPersona($user); $telefonoMovil->setPersona($user); //$documento->setPersona($user); /*$documentoidentidad = $em->getRepository('UBVSurUbvBundle:DocumentoidentidadTipo')->findOneById(2); $nacionalidad->setDocumentoIdentidadTipo($documentoidentidad); $nacionalidad->setIdentificacion(17404055); $estatusAspirante = $em->getRepository('UBVSurUbvBundle:AspiranteTipo')->findOneById(2); $aspirante->setAspiranteTipo($estatusAspirante);*/ $form->setData($user); }else{ $aspiranteTipo = $em->getRepository('UBVSurUbvBundle:AspiranteTipo')->findOneById(4); $periodoAcademicoActivo= $em->getRepository('UBVSurUbvBundle:PeriodoAcademico')->findObjetoPeriodoAcademicoByEstatus(); //die(var_dump($periodoAcademicoActivo)); $estatusAspirante = $em->getRepository('UBVSurUbvBundle:AspiranteEstatus')->findOneById(2); $correoTipo = $em->getRepository('UBVSurUbvBundle:CorreoTipo')->findOneByDescripcion("Personal"); $tipoDocumentoIdentificacion = $em->getRepository('UBVSurUbvBundle:DocumentoIdentidadTipo')->findOneById($datosFormulario["tipoDocumentoIdentificacion"]); $numIdentificacion = intval($datosFormulario["identificacion"]); $nivelPrograma = $datosFormulario["programaNivel"]; $primerNombre = $datosFormulario["primerNombre"]; $segundoNombre = $datosFormulario["segundoNombre"]; $primerApellido = $datosFormulario["primerApellido"]; $segundoApellido = $datosFormulario["segundoApellido"]; $grupo = "Aspirante"; $gruposAsignar = $em->getRepository('UBVSurUbvBundle:Grupo')->findObjetoGrupoByDescripcion($grupo); $user = $userManager->createUser(); $user->setEnabled(false); $user->setPrimerNombre($primerNombre); $user->setSegundoNombre($segundoNombre); $user->setPrimerApellido($primerApellido); $user->setSegundoApellido($segundoApellido); $cuentaInstitucional = $this->generarCorreoInstitucionalAspiranteAction($primerNombre, $segundoNombre, $primerApellido, $segundoApellido); $user->setUsername($cuentaInstitucional.'_ubv'); $user->setEmail($datosFormulario["correoPersonal"]); $correoPersonal = $cuentaInstitucional.'@surubv.edu.ve'; $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if($objetoProgramaNivel->getDescripcion() == 'Pre-Grado'){ $form = $formFactory->createForm(); $template = 'FOSUserBundle:Registration:register.html.twig'; }elseif($objetoProgramaNivel->getDescripcion() == 'Post-Grado'){ $form = $this->createForm(RegistrationAspirantePostGradoType::class); $template = 'FOSUserBundle:Registration:register_postgrado.html.twig'; $deposito = new Deposito(); $user->getDepositos()->add($deposito); $deposito->setPersona($user); //die(var_dump("En postgrado")); }else{ die(var_dump("Opcion Invalida")); } //$form = $formFactory->createForm(); //$datos_aspirante = $request->get('registro_aspirante'); //$tipoDoc = $em->getRepository("UBVSurUbvBundle:DocumentoIdentidadTipo")->findOneById($datos_aspirante["tipoDocumentoIdentificacion"]); $aspirante = new Aspirante(); $nacionalidad = new PersonaNacionalidad(); $telefonoMovil = new PersonaTelefono(); //$documento = new EstudianteDocumento(); $personaCorreo = new PersonaCorreo(); $personaCorreo->setCorreo($correoPersonal); $personaCorreo->setCorreoTipo($correoTipo); $aspirante->setPeriodoAsignado($periodoAcademicoActivo["descripcion"]); $aspirante->setAspiranteTipo($aspiranteTipo); //$nacionalidad->setDocumentoIdentidadTipo($tipoDocumentoIdentificacion); $nacionalidad->setIdentificacion($numIdentificacion); //die((var_dump($session->get('datosFormulario')))); $nacionalidad->setDocumentoIdentidadTipo($tipoDocumentoIdentificacion); $user->getAspirantes()->add($aspirante); $user->getPersonaNacionalidads()->add($nacionalidad); $user->getPersonaTelefonos()->add($telefonoMovil); //$user->getEstudianteDocumentos()->add($documento); $user->getPersonaCorreos()->add($personaCorreo); $aspirante->setPersona($user); $nacionalidad->setPersona($user); $nacionalidad->setEstatus(true); $personaCorreo->setPersona($user); $telefonoMovil->setPersona($user); //$documento->setPersona($user); /*$documentoidentidad = $em->getRepository('UBVSurUbvBundle:DocumentoidentidadTipo')->findOneById(2); $nacionalidad->setDocumentoIdentidadTipo($documentoidentidad); $nacionalidad->setIdentificacion(17404055); $estatusAspirante = $em->getRepository('UBVSurUbvBundle:AspiranteTipo')->findOneById(2); $aspirante->setAspiranteTipo($estatusAspirante);*/ $form->setData($user); } } $form->handleRequest($request); //die(dump($form->get('personaTelefonos')->get('0')->get('telefonoCodigoArea')->getData()->getDescripcion())); //die(dump($form->get('personaTelefonos')->get('0')->get('telefonoCodigoArea')->getData()->getDescripcion())); //die(dump($request)); if ($form->isSubmitted()) { if ($form->isValid()) { $telefono = rawurlencode($form->get('personaTelefonos')->get('0')->get('telefono')->getData()); $codigoAreaTelefono = rawurlencode($form->get('personaTelefonos')->get('0')->get('telefonoCodigoArea')->getData()->getDescripcion()); $numeroTelefono = $codigoAreaTelefono.$telefono; /*$file = $documento->getRutaDocumento(); $fileName = $this->get('ubv.archivo_uploader')->upload($file); $documento->setRutaDocumento($fileName); $user->getEstudianteDocumentos()->add($documento);*/ $aspirante->setAspiranteEstatus($estatusAspirante); $aspirante->setAspiranteTipo($aspiranteTipo); $aspirante->setPeriodoAsignado($periodoAcademicoActivo["descripcion"]); $user->setGroups($gruposAsignar); $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event); $userManager->updateUser($user); $mensaje = "Esto es una Prueba de Envio de SMS de Sur@Ubv favor informar que recibio el mensaje"; $mensajeCodificado = rawurlencode($mensaje); $urlsms= "http://sms9419.ubv.edu.ve:8766/"; $token = rawurlencode("waeTushaph9ohsah#"); $smsUrl = $urlsms.'?number='.$numeroTelefono.'&message='.$mensajeCodificado.'&token='.$token; $this->get('ubv.envio_sms')->enviarSms($smsUrl); if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_registration_confirmed'); //$url = $this->generateUrl('ubv_principal'); $response = new RedirectResponse($url); } $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); return $response; } //die(dump($form->getData())); $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event); if (null !== $response = $event->getResponse()) { return $response; } } return $this->render($template, array( 'form' => $form->createView(), //'registro_aspirante'=>$datos_aspirante, )); } } public function validacionTipoAspiranteAction($datosFormulario){ $em = $this->getDoctrine()->getManager(); $programaNivel = $em->getRepository('UBVSurUbvBundle:ProgramaNivel')->findProgramaNivelById($datosFormulario["programaNivel"]); if($programaNivel["descripcion"] === 'Post-Grado'){ $existePersona = $em->getRepository('UBVSurUbvBundle:Persona')->findPersonaByIdentificacion($datosFormulario); if (!is_null($existePersona)) { $existeEstudiante = $em->getRepository('UBVSurUbvBundle:Persona')->findEstudianteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeEstudiante == false) { $existeAspirante = $em->getRepository('UBVSurUbvBundle:Persona')->findAspiranteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeAspirante == false) { $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { die(dump("Exite en persona pero no en candidato")); return array("tipoValidacion" => "Persona", "datos" => $existePersona); //return false; } else { die(dump("Existe como Candidato")); return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } } else { return array("tipoValidacion" => "Aspirante", "datos" => $existeAspirante); } } else { return array("tipoValidacion" => "Estudiante", "datos" => $existeEstudiante); } }else{ $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { //Es comunidad y pasa a formulario de registro de aspirantes directo return false; } else { return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } } }elseif($programaNivel["descripcion"] === 'Pre-Grado'){ $existePersona = $em->getRepository('UBVSurUbvBundle:Persona')->findPersonaByIdentificacion($datosFormulario); if (!is_null($existePersona)) { $existeEstudiante = $em->getRepository('UBVSurUbvBundle:Persona')->findEstudianteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeEstudiante == false) { $existeAspirante = $em->getRepository('UBVSurUbvBundle:Persona')->findAspiranteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeAspirante == false) { $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { die(dump("Exite en persona pero no en candidato")); return array("tipoValidacion" => "Persona", "datos" => $existePersona); //return false; } else { die(dump("Existe como Candidato")); return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } } else { return array("tipoValidacion" => "Aspirante", "datos" => $existeAspirante); } } else { return array("tipoValidacion" => "Estudiante", "datos" => $existeEstudiante); } }else{ $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { // Es Comunidad hay que evaluar el prceso de verificacion de aldeas que acepten comunidad die(dump("proceso de verificacion de aldeas que aceptwen comunidad"));return false; } else { return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } } } $existePersona = $em->getRepository('UBVSurUbvBundle:Persona')->findPersonaByIdentificacion($datosFormulario); if (!is_null($existePersona)) { $existeEstudiante = $em->getRepository('UBVSurUbvBundle:Persona')->findEstudianteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeEstudiante == false) { $existeAspirante = $em->getRepository('UBVSurUbvBundle:Persona')->findAspiranteByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeAspirante == false) { // Buscar en Archivo o en Entidad sino Existe Retornar al register por Comunidad $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { die(dump("Exite en persona pero no en candidato")); return array("tipoValidacion" => "Persona", "datos" => $existePersona); //return false; } else { die(dump("alkfns")); return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } } else { return array("tipoValidacion" => "Aspirante", "datos" => $existeAspirante); } } else { return array("tipoValidacion" => "Estudiante", "datos" => $existeEstudiante); } } else { $existeCandidato = $em->getRepository('UBVSurUbvBundle:Persona')->findCandidatoByIdentificacionPersonaAndNivelPrograma($datosFormulario); if ($existeCandidato == false) { die(dump("No existe el candidato por lo tanto es comunidad")); //return false; } else { return array("tipoValidacion" => "Candidato", "datos" => $existeCandidato); } return false; } } /** * @Route("/registro_denegado/", name="denegar_registro") * */ public function registroAspiranteDenegadoAction($tipoValidacion, $datos) { //die(dump($tipoValidacion)); return $this->render('UBVAutenticacionBundle:Registration:registro_aspirante_denegado.html.twig', array( 'tipoValidacion' => $tipoValidacion, 'NombreApellido' => $datos[0]["PrimerNombre"] . " " . $datos[0]["PrimerApellido"], 'datos' => $datos )); } public function generarCorreoInstitucionalAspiranteAction($primerNombre, $segundoNombre, $primerApellido, $segundoApellido) { $em = $this->getDoctrine()->getManager(); $cuentasAspirantes = $em->getRepository('UBVSurUbvBundle:Persona')->findCuentasAspirantes(); //die(var_dump($cuentasAspirantes)); $primerNombre = preg_replace('[\s+]','', $primerNombre); $segundoNombre = preg_replace('[\s+]','', $segundoNombre); $primerApellido = preg_replace('[\s+]','', $primerApellido); $segundoApellido = preg_replace('[\s+]','',$segundoApellido); //Regla #1 $nuevaCuenta = strtolower(substr(trim($primerNombre), 0, 1) . (trim($primerApellido))); //die(dump($nuevaCuenta)); if(strlen($nuevaCuenta)>3 && !in_array($nuevaCuenta."_ubv", $cuentasAspirantes)){ return $nuevaCuenta; } elseif (strlen($segundoNombre) > 0 && strlen($segundoApellido) > 0){ //Regla #2 $nuevaCuenta = strtolower(substr(trim($primerNombre), 0, 1) . (substr(trim($segundoNombre), 0, 1)) . (trim($primerApellido))); //Si no existe la nueva cuenta, entonces lo reservamos if (!in_array($nuevaCuenta."_ubv", $cuentasAspirantes)) { return $nuevaCuenta; } else{ //Regla #3 $nuevaCuenta = strtolower(substr(trim($primerNombre), 0, 1) . (substr(trim($segundoNombre), 0, 1)) . (trim($primerApellido)) . (substr(trim($segundoApellido), 0, 1))); //Si no existe la nueva cuenta, entonces lo reservamos if (!in_array($nuevaCuenta."_ubv", $cuentasAspirantes)) { return $nuevaCuenta; } else { //Regla #4 $nuevaCuenta = strtolower(substr(trim($primerNombre), 0, 2) . (substr(trim($segundoNombre), 0, 1)) . (trim($primerApellido)) . (substr(trim($segundoApellido), 0, 1))); //Si no existe la nueva cuenta, entonces lo reservamos if (!in_array($nuevaCuenta."_ubv", $cuentasAspirantes)) { return $nuevaCuenta; } else{ //Regla #5 $nuevaCuenta = strtolower(substr(trim($primerApellido), 0, 1) . (substr(trim($primerNombre), 0, 1))); //Si no existe la nueva cuenta, entonces lo reservamos if (!in_array($nuevaCuenta."_ubv", $cuentasAspirantes)) { return $nuevaCuenta; } } } } } else{ //Regla #6 for ($i = 2; $i < (strlen($primerNombre) + 1); $i++) { $nuevaCuenta = strtolower(substr(trim($primerNombre), 0, $i) . (trim($primerApellido))); //Si no existe la nueva cuenta, entonces lo reservamos if (!in_array($nuevaCuenta."_ubv", $cuentasAspirantes)) { return $nuevaCuenta; break; } } } } /** * Tell the user to check his email provider */ public function checkEmailAction() { $email = $this->get('session')->get('fos_user_send_confirmation_email/email'); $correoPersonal = $this->get('session')->get('fos_user_personal_email/email'); if (empty($email)) { return new RedirectResponse($this->get('router')->generate('fos_user_registration_register')); } $this->get('session')->remove('fos_user_send_confirmation_email/email'); $this->get('session')->remove('fos_user_personal_email/email'); $user = $this->get('fos_user.user_manager')->findUserByEmail($email); if (null === $user) { throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email)); } return $this->render('FOSUserBundle:Registration:check_email.html.twig', array( 'user' => $user, 'correoPersonal'=> $correoPersonal, )); } /** * Receive the confirmation token from user email provider, login the user * * @param Request $request * @param string $token * * @return Response */ public function confirmAction(Request $request, $token) { /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ $userManager = $this->get('fos_user.user_manager'); $user = $userManager->findUserByConfirmationToken($token); if (null === $user) { throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token)); } /** @var $dispatcher EventDispatcherInterface */ $dispatcher = $this->get('event_dispatcher'); $user->setConfirmationToken(null); $user->setEnabled(true); $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM, $event); $userManager->updateUser($user); if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_registration_confirmed'); $response = new RedirectResponse($url); } $dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRMED, new FilterUserResponseEvent($user, $request, $response)); return $response; } /** * Tell the user his account is now confirmed */ public function confirmedAction() { $user = $this->getUser(); //die(dump($user->getRoles())); /*if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException('This user does not have access to this section.'); }*/ return $this->render('FOSUserBundle:Registration:confirmed.html.twig', array( 'user' => $user, 'targetUrl' => $this->getTargetUrlFromSession(), )); } /** * @return mixed */ private function getTargetUrlFromSession() { // Set the SecurityContext for Symfony <2.6 if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) { $tokenStorage = $this->get('security.token_storage'); } else { $tokenStorage = $this->get('security.context'); } $key = sprintf('_security.%s.target_path', $tokenStorage->getToken()->getProviderKey()); if ($this->get('session')->has($key)) { return $this->get('session')->get($key); } } }