static function createByTokenAndUser($token, sfUser $user)
 {
     $rpx = new RPX();
     $response = $rpx->call('auth_info', array('token' => $token));
     if ($response->stat == 'ok') {
         //Save if not found already
         if (!Doctrine::getTable('sfAuthIdentity')->findOneByUrl($response->profile->identifier)) {
             //Assign
             $identity = new sfAuthIdentity();
             $identity->sf_auth_user_id = $user->getId();
             $identity->url = $response->profile->identifier;
             $identity->provider = $response->profile->providerName;
             //Save
             return $identity->save();
         }
         return 'Identity already exists';
     }
     return 'Could not retrieve user profile from partner';
 }
 public function findOneByIdUser($id, sfUser $user)
 {
     $q = $this->createQuery('i');
     $q->addWhere('i.id = ? AND i.sf_auth_user_id = ?', array($id, $user->getId()));
     return $q->fetchOne();
 }
Example #3
0
 /**
  * Create a new blog post.
  * 
  * @throws sfInvalidException 	If a post with this slug already exists
  * 
  * @param string $post_slug 	The post slug (permalink)
  * @param string $post_title 	The post title
  * @param string $post_body 	The post body
  * @param sfUser $post_author	The authot's sfUser (or derivative) object
  * @param string $category 		An optional category for separating blog posts
  * @return sfBlogPost 			The generated object
  */
 public static function makePost($slug, $post_title, $post_body, sfUser $post_author, $category = NULL)
 {
     $slug_check = sfCore::$db->query("SELECT count(*) FROM `swossh_blog_posts` WHERE `slug` = %s LIMIT 1;");
     if ($slug_check->fetchScalar() == 1) {
         throw new sfInvalidException(array('slug' => sfInvalidException::EXISTING));
     }
     $new_post = sfCore::$db->query("INSERT INTO `swoosh_blog_posts` (\n\t\t\t`post_id`, `title`, `author_id`, `timestamp`, `category`, `comments_enabled`, `slug`)\n\t\t\tVALUES (\n\t\t\t\tNULL, %s, %i, NOW(), %s, 1, %s)", $post_title, $post_author->getId(), $category, $slug);
     $post_body = sfCore::$db->query("INSERT INTO `swoosh_blog_contents` (\n\t\t\t`post_id`, `content`)\n\t\t\tVALUES (%i, %s)", $new_post->getAutoIncrementedValue(), $post_body);
     $obj = sfCore::make('sfBlogPost');
     $obj->load($new_post->getAutoIncrementedValue());
     return $obj;
 }