/**
  * executeRegister
  *
  * @access public
  * @return void
  */
 public function executeRegister(sfWebRequest $request)
 {
     $this->form = new sfGuardFormRegister();
     if ($request->isMethod(sfRequest::POST)) {
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $values = $this->form->getValues();
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->fromArray($values, BasePeer::TYPE_FIELDNAME);
             if (isset($values['email'])) {
                 $sfGuardUser->setEmail($values['email']);
             }
             $sfGuardUser->setIsActive(false);
             $sfGuardUser->save();
             $messageParams = array('sfGuardUser' => $sfGuardUser, 'password' => $values['password']);
             $body = $this->getComponent($this->getModuleName(), 'send_request_confirm', $messageParams);
             $from = sfConfig::get('app_sf_guard_extra_plugin_mail_from', '*****@*****.**');
             $fromName = sfConfig::get('app_sf_guard_extra_plugin_name_from', 'noreply');
             $to = $sfGuardUser->getEmail();
             $toName = $sfGuardUser->getUsername();
             $subject = sfConfig::get('app_sf_guard_extra_plugin_subject_confirm', 'Confirm Registration');
             $mailer = $this->getMailer();
             $message = $mailer->compose(array($from => $fromName), array($to => $toName), $subject, $body);
             $mailer->send($message);
             $this->getUser()->setFlash('values', $values);
             $this->getUser()->setFlash('sfGuardUser', $sfGuardUser);
             return $this->redirect('@sf_guard_do_register');
         }
     }
 }
$msg2->setUserId($user2->getId());
$msg2->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 2, 'Adding a second message increments the topic number of posts');
$t->is($topic->getNbReplies(), 1, 'A topic can calculate its number of replies based on its number of posts');
$t->is($topic->getUpdatedAt('U'), $msg2->getCreatedAt('U'), 'Adding a second message changes the latest reply date of the topic to the message creation date');
$t->is($topic->getLatestPost()->getAuthorName(), $user2->getUsername(), 'Adding a second message changes the latest reply author name to the message author name');
sleep(1);
$msg3 = new sfSimpleForumPost();
$msg3->setTopicId($topic->getId());
$msg3->setUserId($user3->getId());
$msg3->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 3, 'Adding a third message increments the topic number of replies');
$t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Adding a third message changes the latest reply date of the topic to the message creation date');
$t->is($topic->getLatestPost()->getAuthorName(), $user3->getUsername(), 'Adding a third message changes the latest reply author name to the  message author name');
$t->diag('Updating a message');
sleep(1);
$msg1 = sfSimpleForumPostPeer::retrieveByPk($msg1->getId());
$msg1->setTitle('this is a test');
$msg1->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 3, 'Updating a message doesn\'t change the topic post count');
$t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the topic\'s last update date');
$t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the topic\'s latest reply');
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId());
$t->is($forum->getNbPosts(), 3, 'Updating a message doesn\'t change the forum\'s post count');
$t->is($forum->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the forum\'s last update date');
$t->is($forum->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the forum\'s last reply');
$t->diag('Updating the topic');
sleep(1);
 protected function createUserAndProfile($username, $con = null)
 {
     // no user with this username
     if (null === $con) {
         $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         // create a new user object
         $user = new sfGuardUser();
         $user->setUsername($username);
         $user->setIsActive(1);
         $user->setAlgorithm('');
         $user->save($con);
         // do we have a profile in the system with this net_id?
         // this could happen if the profile was added manually by an admin
         $userProfile = UserProfilePeer::selectByNetIdWithNoUserId($username);
         if ($userProfile) {
             // there is already a dangling user profile with this net id, link the user with the profile
             $userProfile->setUserId($user->getId());
             $userProfile->save($con);
         } else {
             // make a new user profile
             $userProfile = new UserProfile();
             $userProfile->setUserId($user->getId());
             $userProfile->setNetId($user->getUsername());
             $userProfile->save($con);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
     return $user;
 }
Example #4
0
 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';
     }
 }