protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $c = new Criteria(); $c->addJoin(SfGuardUserPeer::ID, SfGuardUserProfilePeer::USER_ID); $c->add(SfGuardUserProfilePeer::FACEBOOK_UID, null, Criteria::ISNOTNULL); $c->add(SfGuardUserProfilePeer::NOMBRE, '', Criteria::EQUAL); $c->add(SfGuardUserPeer::IS_ACTIVE, 1); $profiles = SfGuardUserProfilePeer::doSelect($c); foreach ($profiles as $profile) { $data = VoFacebook::getData($profile->getFacebookUid()); if ($data) { echo $data->name . "\n"; $profile->setNombre($data->first_name); $profile->setApellidos($data->last_name); $profile->save(); } } }
public function executeSignin($request) { $this->op = $request->getParameter('op'); //echo $this->op; //die; $dialog = $request->getParameter('dialog', false); /* IF FB CONNECT */ if ($this->op == 'fbc' && ($facebook_uid = VoFacebook::getUid())) { //echo "FBC";die; $c = new Criteria(); $c->addJoin(SfGuardUserProfilePeer::USER_ID, SfGuardUserPeer::ID); $c->add(SfGuardUserProfilePeer::FACEBOOK_UID, $facebook_uid); $sfGuardUser = SfGuardUserPeer::doSelectOne($c); if (!$sfGuardUser instanceof sfGuardUser) { // Comprobación de que no existe ya el usuario con ese username (bug #734) $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, 'Facebook_' . $facebook_uid); $existingUser = sfGuardUserPeer::doSelectOne($c); if ($existingUser) { $existingUser->setUsername('Facebook_' . $facebook_uid . '-' . time()); $existingUser->save(); } $sfGuardUser = new sfGuardUser(); $sfGuardUser->setUsername('Facebook_' . $facebook_uid); $sfGuardUser->save(); $voProfile = $sfGuardUser->getProfile(); $vanityUrl = SfVoUtil::encodeVanity('Facebook_' . $facebook_uid); $voProfile->setFacebookUid($facebook_uid); if (!$voProfile->getNombre()) { $data = VoFacebook::getData($voProfile->getFacebookUid()); $voProfile->setNombre($data->first_name); $voProfile->setApellidos($data->last_name); } $c2 = new Criteria(); $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2); $counter = 0; foreach ($usuariosLikeMe as $usuarioLikeMe) { if (preg_match("/^Facebook_{$facebook_uid}-([0-9]*)/i", $usuarioLikeMe->getVanity(), $matches)) { $curIdx = $matches[1]; if ($curIdx > $counter) { $counter = $curIdx + 1; } } else { $counter++; } } $voProfile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}")); $voProfile->setMailsComentarios(0); $voProfile->setMailsNoticias(0); $voProfile->setMailsContacto(0); $voProfile->setMailsSeguidor(0); $voProfile->save(); } $this->getUser()->signin($sfGuardUser, false); $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $this->getUser()->getReferer('@homepage')); $this->redirect($signinUrl); } /* FI FB CONNECT */ $this->registrationform = new RegistrationForm(); $this->signinform = new SigninForm(); if ($request->isMethod('post') && !$dialog) { // Register if ($this->op == 'r') { $this->registrationform = new RegistrationForm(); $this->registrationform->bind($request->getParameter('registration')); if ($this->registrationform->isValid()) { $user = new sfGuardUser(); $user->setUsername($this->registrationform->getValue('username')); $user->setPassword($this->registrationform->getValue('password')); $user->setIsActive(0); $user->setCreatedAt(time()); $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $user->getUsername()); sfGuardUserPeer::doInsert($user); $user = sfGuardUserPeer::doSelect($c); if (count($user) == 1) { $profile = $user[0]->getProfile(); $profile->setNombre($this->registrationform->getValue('nombre')); $profile->setApellidos($this->registrationform->getValue('apellidos')); $profile->setPresentacion($this->registrationform->getValue('presentacion')); $profile->setAnonymous($this->registrationform->getValue('anonymous')); $profile->setCodigo(util::generateUID()); /* Generar vanity */ if ($profile->getVanity() == '') { $vanityUrl = SfVoUtil::encodeVanity($profile->getNombre() . "-" . $profile->getApellidos()); $c2 = new Criteria(); $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); $c2->add(SfGuardUserProfilePeer::ID, $user[0]->getId(), Criteria::NOT_EQUAL); $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2); $counter = 0; foreach ($usuariosLikeMe as $usuarioLikeMe) { $counter++; } $profile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}")); } /* Fin Generar vanity */ sfGuardUserProfilePeer::doInsert($profile); $this->sendWelcome($user[0]); $this->user = $user[0]; return "Registered"; } } /* else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false); } */ } else { $r = new SigninForm(); $r->bind($request->getParameter('signin')); if ($r->isValid()) { $r->addPostValidation(); $r->bind($request->getParameter('signin')); if ($r->isValid()) { $this->doSignin($request, $this->op); } } /* else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false); } */ $this->signinform = $r; } } $this->title = sfContext::getInstance()->getI18N()->__('Acceso usuarios', array()); $this->title .= ' - Voota'; $this->response->setTitle($this->title); if ($this->op == 'fb') { return 'FB'; } }