<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brit Gardner &#187; bbpress</title>
	<atom:link href="http://britg.com/tags/bbpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://britg.com</link>
	<description>The big yellow one&#039;s the sun.</description>
	<lastBuildDate>Thu, 15 Mar 2012 14:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Integrating CakePHP with bbPress &#8211; Part 2</title>
		<link>http://britg.com/2008/08/25/integrating-cakephp-with-bbpress-part-2/</link>
		<comments>http://britg.com/2008/08/25/integrating-cakephp-with-bbpress-part-2/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 12:50:33 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[bbpress]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://britg.com/?p=392</guid>
		<description><![CDATA[This is the second of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x. When complete, these 3 tutorials will accomplish: Integrating bbPress in a sub-folder (not a subdomain) of your cake install (part 1 here) Integrating user registration &#8211; when a user registers through your cake application they are automatically registered [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the second of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x.  When complete, these 3 tutorials will accomplish:</em></p>
<ol>
<li><em>Integrating bbPress in a sub-folder (not a subdomain) of your cake install (<a href="http://britg.com/2008/08/23/integrating-cakephp-with-bbpress-part-1/">part 1 here</a>)<br />
</em></li>
<li><em>Integrating user registration &#8211; when a user registers through your cake application they are automatically registered in bbPress.</em></li>
<li><em>Integrating the login &#8211; when a user is logged in via the cake application they are automatically logged in in bbPress.</em></li>
</ol>
<h3>Part 2 &#8211; Integrating User Registration</h3>
<p>This part is a little more tricky, but not unmanageable.   The challenge here is that your Cake application probably uses the Auth component, or a custom user setup.  So you probably have a prebuilt users table and chances are it does not conform to what bbPress is looking for in it&#8217;s users table.  Also, the encryption scheme between the two is probably different.</p>
<p>With that in mind, I&#8217;ve made the following design decisions</p>
<ol>
<li>My Cake users schema will remain intact <em>AND</em> the bbPress users schema will remain intact.</li>
<li>Users must register through my Cake application only</li>
<li>CakePHP is using the built-in Auth component.</li>
<li>When a user registers through my Cake application &#8211; I run the necessary logic from the Cake <code>User</code> model to update the bbPress users table.</li>
<li>The bbPress tables are in the same database as my CakePHP tables</li>
<li>I change the encryption scheme of bbPress to conform to my Cake app.</li>
</ol>
<h4>Step 1: changing the bbPress password encryption.</h4>
<p>If you&#8217;ve followed <a href="http://britg.com/2008/08/23/integrating-cakephp-with-bbpress-part-1/">Part 1</a> of this tutorial, you&#8217;ve successfully installed and ran bbPress in a subfolder of your cakephp install.  Navigate to that subfolder, then open following file: <code>bb-includes/backpress/code.wp-pass.php</code></p>
<p>Notice two functions, <code>hash_password(...)</code> and <code>check_password(...)</code>.  We will overwrite these two functions to match the hashing that takes place in our CakePHP install.  If, as I denoted above, you are using the built-in CakePHP Auth component, this is very simple &#8211; just comment out the existing functions and replace them with the following:</p>
<pre lang="php">	function hash_password($string) {
		$string = 'YOUR CONFIGURE::SALT VALUE'.$string;
		return sha1($string);
	}

	function check_password($password, $hash, $user_id = '') {
		$string = 'YOUR CONFIGURE::SALT VALUE'.$password;
		if(sha1($string) != $hash) {
			return false;
		} else {
			return true;
		}
	}</pre>
<p>Replace the <code>YOUR CONFIGURE::SALT VALUE</code> with the appropriate value from your CakePHP application.  This can be found in <code>app/config/core.php</code>.</p>
<p>With these two functions in place, your bbPress user system should be hashing and checking the passwords the same way.</p>
<h4>Step 2: Saving a bbPress user from the CakePHP install.</h4>
<p>Fortunately, CakePHP provides an easy hook into the ORM saving process with the <code>afterSave()</code> model callback.</p>
<p>To get your User model to save a new bbPress user when a new Cake user is created, add the following functions to your User model script:</p>
<pre lang="php">	function afterSave($created)
	{
		if($created)
		{
			$sql = "INSERT INTO `bb_users`
			(`user_login`, `user_pass`, `user_nicename`,
			`user_email`, `user_url`, `user_registered`,
			`user_status`, `display_name`)
			VALUES(
			'".$this-&gt;data['User']['username']."',
			'".$this-&gt;data['User']['password']."',
			'".$this-&gt;data['User']['username']."',
			'".$this-&gt;data['User']['email']."',
			'',
			NOW(),
			0, '".$user['User']['username']."')";
			$this-&gt;query($sql);
		}
	}</pre>
<p>Notice that we are just creating an SQL statement with all the necessary fields required to successfully insert the user into the bbPress system, and then executing that SQL.  Also, if you are using the default functionality of the Auth component, <code>$this->data['User']['password'];</code> should automatically be hashed with the same scheme as Step 1.</p>
<h4>Step 3 &#8211; Preventing registration from bbPress</h4>
<p>This is the easy part.  Simply add the following line to the top of your <code>register.php</code> script in you bbPress install and replace the path with the correct path to your cake registration page.</p>
<pre lang="php">die(header('Location: /path/to/your/cake/registration/page'));</pre>
<p>So, that&#8217;s it!  Now, when you register a user through your Cake application, they should also appear in the bbPress users table, and you should be able to successfully log into both with the exact same credentials.</p>
<p>But, the plot thickens &#8211; we don&#8217;t want our users to have to log in to both the cake app and bbpress.  We want them to be logged into both automatigically.  Stay tuned for part 3 of this tutorial and I&#8217;ll attempt to tackle this very conundrum. </p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2008/08/25/integrating-cakephp-with-bbpress-part-2/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Integrating CakePHP with bbPress &#8211; Part 1</title>
		<link>http://britg.com/2008/08/23/integrating-cakephp-with-bbpress-part-1/</link>
		<comments>http://britg.com/2008/08/23/integrating-cakephp-with-bbpress-part-1/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 22:13:57 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[bbpress]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://britg.com/?p=384</guid>
		<description><![CDATA[I&#8217;ve been working on StatForge.com for the past few days and one of the community features I want to integrate is a forum.  Rather than go for something bloated like phpbb or vanilla, I decided to go with bbPress from the makers of WordPress. This is the first of a 3 part tutorial on how [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on <a href="http://statforge.com">StatForge.com</a> for the past few days and one of the community features I want to integrate is a forum.  Rather than go for something bloated like phpbb or vanilla, I decided to go with <a href="http://bbpress.org">bbPress</a> from the makers of <a href="http://wordpress.org">WordPress</a>.</p>
<p>This is the first of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x.  When complete, these 3 tutorials will accomplish:</p>
<ol>
<li>Integrating bbPress in a sub-folder (not a subdomain) of your cake install</li>
<li>Integrating user registration &#8211; when a user registers through your cake application they are automatically registered in bbPress. (UPDATE: <a href="http://britg.com/2008/08/25/integrating-cakephp-with-bbpress-part-2/">part 2 here</a>)</li>
<li>Integrating the login &#8211; when a user is logged in via the cake application they are automatically logged in in bbPress.</li>
</ol>
<h3>Part 1 &#8211; Integrating bbPress in a sub-folder (not a subdomain)</h3>
<p>It may be personal preference, but I&#8217;m not a big fan of subdomaining parts of an application.  There are definitely legitamite technical reasons to do so, but when I can get away with it, I try to use subfolders, i.e. <code><a href="http://statforge.com" rel="nofollow">http://statforge.com</a></code> and <code><a href="http://statforge.com/forum/" rel="nofollow">http://statforge.com/forum/</a></code>.</p>
<p>There&#8217;s a small hurdle here since CakePHP wants to ReWrite all your paths (if you&#8217;ve installed it in your domain root), but it&#8217;s easy to overcome.  Find the <code>.htaccess</code> file in the root of your cake install.  It should look like this:</p>
<pre lang="bash">   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]</pre>
<p>This is rewriting all of your requests to the webroot folder.  Assuming you want to install bbPress into a subfolder called <code>forum</code> (i.e. <code><a href="http://statforge.com/forum/" rel="nofollow">http://statforge.com/forum/</a></code>) the change this <code>.htaccess</code> file to the following:</p>
<pre lang="bash">   RewriteEngine on

   RewriteCond %{REQUEST_URI} ^/forum/(.*)$
   RewriteRule ^.*$ - [L]

   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]</pre>
<p>This simply reads &#8211; if the Request starts with <code>/forum/</code> pass it through normally.  If not, let Cake handle it.  The only limitation here is that you cannot have a controller named &#8216;forum&#8217; in your cake application.</p>
<p>That&#8217;s it &#8211; you should be able to drop a fresh bbPress install into the /forum subfolder and access it normally without Cake interfering.</p>
<p>I&#8217;ve already integrated the user registration between my CakePHP install and my bbPress install, but I&#8217;ve gotta run for the time being.  Hopefully tomorrow I&#8217;ll throw up part 2 &#8211; it&#8217;s a bit more complicated. (UPDATE: <a href="http://britg.com/2008/08/25/integrating-cakephp-with-bbpress-part-2/">part 2 here</a>)</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2008/08/23/integrating-cakephp-with-bbpress-part-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

