<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: CakePHP &#8211; Activating User Account via Email</title>
	<atom:link href="http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/</link>
	<description>Actionscript, Flash, PHP and stuff</description>
	<lastBuildDate>Thu, 11 Mar 2010 06:50:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Lefkon</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-8268</link>
		<dc:creator>David Lefkon</dc:creator>
		<pubDate>Tue, 02 Mar 2010 08:40:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-8268</guid>
		<description>Nice tutorial .. thx!

Made a mod that should allow the activation code an additional day before it expires:

in app/controllers/users_controller:

function register() {
	if (!empty($this-&gt;data)) {
		$this-&gt;User-&gt;create();
		$this-&gt;User-&gt;save($this-&gt;data);
		$this-&gt;Session-&gt;setFlash(&#039;Your account has not been activated yet!&#039;);
		$this-&gt;__sendActivationEmail($this-&gt;User-&gt;getLastInsertID());
		$this-&gt;redirect(&#039;/line&#039;);
	}
}

function __sendActivationEmail($user_id) {
  $user = $this-&gt;User-&gt;find(array(&#039;User.id&#039; =&gt; $user_id), array(&#039;User.id&#039;, &#039;User.email&#039;, &#039;User.username&#039;), null, false);
  if ($user === false) {
          debug(__METHOD__.&quot; failed to retrieve User data for user.id: {$user_id}&quot;);
          return false;
  }
  // Set data for the &quot;view&quot; of the Email
  $this-&gt;set(&#039;activate_url&#039;, &#039;http://&#039; . env(&#039;SERVER_NAME&#039;) . &#039;/users/activate/&#039; . $user[&#039;User&#039;][&#039;id&#039;] . &#039;/&#039; . $this-&gt;User-&gt;getActivationHash());
  $this-&gt;set(&#039;username&#039;, $this-&gt;data[&#039;User&#039;][&#039;username&#039;]);
  $this-&gt;Email-&gt;to = $user[&#039;User&#039;][&#039;email&#039;];
  $this-&gt;Email-&gt;subject = env(&#039;SERVER_NAME&#039;) . &#039; – Please confirm your email address&#039;;
  $this-&gt;Email-&gt;from = &#039;noreply@&#039; . env(&#039;SERVER_NAME&#039;);
  $this-&gt;Email-&gt;template = &#039;user_confirm&#039;;
  $this-&gt;Email-&gt;sendAs = &#039;text&#039;;   // &#039;text&#039;, &#039;html&#039; and &#039;both&#039; are options   
  return $this-&gt;Email-&gt;send();
}
    
function activate($user_id = null, $in_hash = null) {
  $this-&gt;User-&gt;find(array(&#039;User.id&#039; =&gt; $this-&gt;params[&#039;pass&#039;][0]), array(&#039;User.id&#039;, &#039;User.email&#039;, &#039;User.username&#039;), null, false);
  if ($this-&gt;User-&gt;getActivationHash() == $this-&gt;params[&#039;pass&#039;][1] &#124;&#124; $this-&gt;User-&gt;getYesterdaysActivationHash() == $this-&gt;params[&#039;pass&#039;][1])
  {
    // Update the active flag in the database
    $this-&gt;User-&gt;saveField(&#039;active&#039;, 1);
   
    // Let the user know they can now log in!
    $this-&gt;Session-&gt;setFlash(&#039;Your account has been activated, please log in below&#039;);
    $this-&gt;redirect(&#039;login&#039;);
  }
  // Activation failed, render ‘/views/user/activate.ctp’ which should tell the user.
}


... and in app/models/user.php

function getActivationHash()
{
        if (!isset($this-&gt;id)) {
                return false;
        }
        return substr(Security::hash(Configure::read(&#039;Security.salt&#039;) . $this-&gt;field(&#039;created&#039;) . date(&#039;y&#039;) . date(&#039;m&#039;). date(&#039;d&#039;)), 0, 8);
}

function getYesterdaysActivationHash()
{
        if (!isset($this-&gt;id)) {
                return false;
        }
        return substr(Security::hash(Configure::read(&#039;Security.salt&#039;) . $this-&gt;field(&#039;created&#039;) . date(&#039;y&#039;) . date(&#039;m&#039;). date(&#039;d&#039;) - 1), 0, 8);
}</description>
		<content:encoded><![CDATA[<p>Nice tutorial .. thx!</p>
<p>Made a mod that should allow the activation code an additional day before it expires:</p>
<p>in app/controllers/users_controller:</p>
<p>function register() {<br />
	if (!empty($this-&gt;data)) {<br />
		$this-&gt;User-&gt;create();<br />
		$this-&gt;User-&gt;save($this-&gt;data);<br />
		$this-&gt;Session-&gt;setFlash(&#8217;Your account has not been activated yet!&#8217;);<br />
		$this-&gt;__sendActivationEmail($this-&gt;User-&gt;getLastInsertID());<br />
		$this-&gt;redirect(&#8217;/line&#8217;);<br />
	}<br />
}</p>
<p>function __sendActivationEmail($user_id) {<br />
  $user = $this-&gt;User-&gt;find(array(&#8217;User.id&#8217; =&gt; $user_id), array(&#8217;User.id&#8217;, &#8216;User.email&#8217;, &#8216;User.username&#8217;), null, false);<br />
  if ($user === false) {<br />
          debug(__METHOD__.&#8221; failed to retrieve User data for user.id: {$user_id}&#8221;);<br />
          return false;<br />
  }<br />
  // Set data for the &#8220;view&#8221; of the Email<br />
  $this-&gt;set(&#8217;activate_url&#8217;, &#8216;http://&#8217; . env(&#8217;SERVER_NAME&#8217;) . &#8216;/users/activate/&#8217; . $user['User']['id'] . &#8216;/&#8217; . $this-&gt;User-&gt;getActivationHash());<br />
  $this-&gt;set(&#8217;username&#8217;, $this-&gt;data['User']['username']);<br />
  $this-&gt;Email-&gt;to = $user['User']['email'];<br />
  $this-&gt;Email-&gt;subject = env(&#8217;SERVER_NAME&#8217;) . &#8216; – Please confirm your email address&#8217;;<br />
  $this-&gt;Email-&gt;from = &#8216;noreply@&#8217; . env(&#8217;SERVER_NAME&#8217;);<br />
  $this-&gt;Email-&gt;template = &#8216;user_confirm&#8217;;<br />
  $this-&gt;Email-&gt;sendAs = &#8216;text&#8217;;   // &#8216;text&#8217;, &#8216;html&#8217; and &#8216;both&#8217; are options<br />
  return $this-&gt;Email-&gt;send();<br />
}</p>
<p>function activate($user_id = null, $in_hash = null) {<br />
  $this-&gt;User-&gt;find(array(&#8217;User.id&#8217; =&gt; $this-&gt;params['pass'][0]), array(&#8217;User.id&#8217;, &#8216;User.email&#8217;, &#8216;User.username&#8217;), null, false);<br />
  if ($this-&gt;User-&gt;getActivationHash() == $this-&gt;params['pass'][1] || $this-&gt;User-&gt;getYesterdaysActivationHash() == $this-&gt;params['pass'][1])<br />
  {<br />
    // Update the active flag in the database<br />
    $this-&gt;User-&gt;saveField(&#8217;active&#8217;, 1);</p>
<p>    // Let the user know they can now log in!<br />
    $this-&gt;Session-&gt;setFlash(&#8217;Your account has been activated, please log in below&#8217;);<br />
    $this-&gt;redirect(&#8217;login&#8217;);<br />
  }<br />
  // Activation failed, render ‘/views/user/activate.ctp’ which should tell the user.<br />
}</p>
<p>&#8230; and in app/models/user.php</p>
<p>function getActivationHash()<br />
{<br />
        if (!isset($this-&gt;id)) {<br />
                return false;<br />
        }<br />
        return substr(Security::hash(Configure::read(&#8217;Security.salt&#8217;) . $this-&gt;field(&#8217;created&#8217;) . date(&#8217;y') . date(&#8217;m'). date(&#8217;d')), 0, 8);<br />
}</p>
<p>function getYesterdaysActivationHash()<br />
{<br />
        if (!isset($this-&gt;id)) {<br />
                return false;<br />
        }<br />
        return substr(Security::hash(Configure::read(&#8217;Security.salt&#8217;) . $this-&gt;field(&#8217;created&#8217;) . date(&#8217;y') . date(&#8217;m'). date(&#8217;d') &#8211; 1), 0, 8);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ganzgenau</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-7499</link>
		<dc:creator>Ganzgenau</dc:creator>
		<pubDate>Mon, 21 Dec 2009 16:45:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-7499</guid>
		<description>Thanks so much!</description>
		<content:encoded><![CDATA[<p>Thanks so much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ANAND</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-7209</link>
		<dc:creator>ANAND</dc:creator>
		<pubDate>Tue, 24 Nov 2009 06:59:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-7209</guid>
		<description>hi all...
Actually am getting bellow mentioned error

Missing Component File

Error: The component file was not found.

Error: Create the class ‘Auth’Component in file: app\controllers\components\‘auth’.php



Notice: If you want to customize this error message, create app\views\errors\missing_component_file.ctp



not getting wt is the proble...</description>
		<content:encoded><![CDATA[<p>hi all&#8230;<br />
Actually am getting bellow mentioned error</p>
<p>Missing Component File</p>
<p>Error: The component file was not found.</p>
<p>Error: Create the class ‘Auth’Component in file: app\controllers\components\‘auth’.php</p>
<p>Notice: If you want to customize this error message, create app\views\errors\missing_component_file.ctp</p>
<p>not getting wt is the proble&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Siddhartha</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-7142</link>
		<dc:creator>Siddhartha</dc:creator>
		<pubDate>Tue, 17 Nov 2009 02:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-7142</guid>
		<description>Wonderful tutorial.
Just one point to note.

file:// /app/controllers/users_controller.php

Add following line in the UsersController::beforeFilter()
{
...
$this-&gt;Auth-&gt;autoRedirect = false;
...
}
This will allow you to use further checking on login() action.</description>
		<content:encoded><![CDATA[<p>Wonderful tutorial.<br />
Just one point to note.</p>
<p>file:// /app/controllers/users_controller.php</p>
<p>Add following line in the UsersController::beforeFilter()<br />
{<br />
&#8230;<br />
$this-&gt;Auth-&gt;autoRedirect = false;<br />
&#8230;<br />
}<br />
This will allow you to use further checking on login() action.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen Barnhardt</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-5187</link>
		<dc:creator>Glen Barnhardt</dc:creator>
		<pubDate>Fri, 31 Jul 2009 18:47:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-5187</guid>
		<description>Thanks for the great article. I was able to implement this into my latest application with not to much work. Thanks for all the great comments as they helped me to fix the few errors I ran into during the implementation.

Good Job!!</description>
		<content:encoded><![CDATA[<p>Thanks for the great article. I was able to implement this into my latest application with not to much work. Thanks for all the great comments as they helped me to fix the few errors I ran into during the implementation.</p>
<p>Good Job!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diogenes (youngwebmaster)</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-4913</link>
		<dc:creator>Diogenes (youngwebmaster)</dc:creator>
		<pubDate>Tue, 07 Jul 2009 15:11:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-4913</guid>
		<description>@Steppio, @bryan, @Jonny
The problem is the fact that there is a small oversight/typo in the code. 

function activate($user_id = null, $in_hash = null) {
        $this-&gt;User-&gt;id = $id;

should actually be

function activate($user_id = null, $in_hash = null) {
        $this-&gt;User-&gt;id = $user_id;

He referred to $id instead of $user_id, which was the real name of the variable passed to the function via the url, which is why this wouldn&#039;t work/would give you errors if you just copied and pasted the above code. Just goes to show that using someone&#039;s code without really knowing what it&#039;s doing and how is a bad idea.

Cheers!</description>
		<content:encoded><![CDATA[<p>@Steppio, @bryan, @Jonny<br />
The problem is the fact that there is a small oversight/typo in the code. </p>
<p>function activate($user_id = null, $in_hash = null) {<br />
        $this-&gt;User-&gt;id = $id;</p>
<p>should actually be</p>
<p>function activate($user_id = null, $in_hash = null) {<br />
        $this-&gt;User-&gt;id = $user_id;</p>
<p>He referred to $id instead of $user_id, which was the real name of the variable passed to the function via the url, which is why this wouldn&#8217;t work/would give you errors if you just copied and pasted the above code. Just goes to show that using someone&#8217;s code without really knowing what it&#8217;s doing and how is a bad idea.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bryan</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-4766</link>
		<dc:creator>bryan</dc:creator>
		<pubDate>Wed, 10 Jun 2009 03:11:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-4766</guid>
		<description>This article is exactly what I was looking for but I am experiencing a lot of trouble adjusting the code to work with Cake 1.2 - I am new to Cake. Is there a chance someone can clarify what to do for things such as:

__sendActivationEmail(...)
 $user[&#039;User&#039;][&#039;id&#039;]
giving me Undefined index:  id

function activate(...)
 $this-&gt;User-&gt;id = $id;
giving me Undefined variable: id

Any chance someone can port this??

I hope this isn&#039;t a stupid question - Sorry in advance if it is!</description>
		<content:encoded><![CDATA[<p>This article is exactly what I was looking for but I am experiencing a lot of trouble adjusting the code to work with Cake 1.2 &#8211; I am new to Cake. Is there a chance someone can clarify what to do for things such as:</p>
<p>__sendActivationEmail(&#8230;)<br />
 $user['User']['id']<br />
giving me Undefined index:  id</p>
<p>function activate(&#8230;)<br />
 $this-&gt;User-&gt;id = $id;<br />
giving me Undefined variable: id</p>
<p>Any chance someone can port this??</p>
<p>I hope this isn&#8217;t a stupid question &#8211; Sorry in advance if it is!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZedR</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-4638</link>
		<dc:creator>ZedR</dc:creator>
		<pubDate>Thu, 14 May 2009 12:52:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-4638</guid>
		<description>Hi!!

How do I authenticate user without login when user clicks on activate link from email &amp; redirect to an action of different controller(this too authenticated). I dont want the user to login when clicked on activation link &amp; is authenticated automatically. I am new to cakephp. Any help will be appreciated. Thanks.</description>
		<content:encoded><![CDATA[<p>Hi!!</p>
<p>How do I authenticate user without login when user clicks on activate link from email &amp; redirect to an action of different controller(this too authenticated). I dont want the user to login when clicked on activation link &amp; is authenticated automatically. I am new to cakephp. Any help will be appreciated. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: james</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-3259</link>
		<dc:creator>james</dc:creator>
		<pubDate>Thu, 26 Mar 2009 21:04:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-3259</guid>
		<description>I couldn&#039;t get the email to send out an activation link with the user id in it.

To get that to work i had to change in the email function:

$user = $this-&gt;User-&gt;find(array(‘User.id’ =&gt; $user_id), array(‘User.email’, ‘User.username’), null, false);

to this: 

$user = $this-&gt;User-&gt;find(array(&#039;User.id&#039; =&gt; $user_id), array(&#039;User.id&#039;, &#039;User.user_email&#039;, &#039;User.username&#039;), null, false);</description>
		<content:encoded><![CDATA[<p>I couldn&#8217;t get the email to send out an activation link with the user id in it.</p>
<p>To get that to work i had to change in the email function:</p>
<p>$user = $this-&gt;User-&gt;find(array(‘User.id’ =&gt; $user_id), array(‘User.email’, ‘User.username’), null, false);</p>
<p>to this: </p>
<p>$user = $this-&gt;User-&gt;find(array(&#8217;User.id&#8217; =&gt; $user_id), array(&#8217;User.id&#8217;, &#8216;User.user_email&#8217;, &#8216;User.username&#8217;), null, false);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Childs</title>
		<link>http://www.jonnyreeves.co.uk/2008/06/cakephp-activating-user-account-via-email/comment-page-1/#comment-2483</link>
		<dc:creator>Peter Childs</dc:creator>
		<pubDate>Wed, 18 Feb 2009 13:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=42#comment-2483</guid>
		<description>Thanks so much for this - it taught me a lot and helped greatly.

Not that it went totally smoothly - because I&#039;m a neophyte programmer teaching myself cake and php simultaneously and my application is laid out differently with additional code embedded within your email activation framework.

My learning’s from yesterday - beware when you are getting only part of the expected result. I use an Auth based permission system (adapted from another tutorial) that defaults to login when a user isn&#039;t permitted to access a URL. When I clicked the email and went to login I thought everything was working - EXCEPT the active field wasn&#039;t getting updated and I couldn&#039;t understand why.

It took a day, and traipsing through increasingly hair-brained possibilities (and learning new stuff along the way) before doing the obvious, change the redirect page and see whether the activate action was being used. It wasn&#039;t. From there it was just a small step understand what was really going on and add activate to Auth&#039;s before filter list. 

It&#039;s a long story - but without tutorials like yours, teaching oneself to code would be incredibly difficult, and building a functional site (even if it lives on localhost) would be totally impossible. Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks so much for this &#8211; it taught me a lot and helped greatly.</p>
<p>Not that it went totally smoothly &#8211; because I&#8217;m a neophyte programmer teaching myself cake and php simultaneously and my application is laid out differently with additional code embedded within your email activation framework.</p>
<p>My learning’s from yesterday &#8211; beware when you are getting only part of the expected result. I use an Auth based permission system (adapted from another tutorial) that defaults to login when a user isn&#8217;t permitted to access a URL. When I clicked the email and went to login I thought everything was working &#8211; EXCEPT the active field wasn&#8217;t getting updated and I couldn&#8217;t understand why.</p>
<p>It took a day, and traipsing through increasingly hair-brained possibilities (and learning new stuff along the way) before doing the obvious, change the redirect page and see whether the activate action was being used. It wasn&#8217;t. From there it was just a small step understand what was really going on and add activate to Auth&#8217;s before filter list. </p>
<p>It&#8217;s a long story &#8211; but without tutorials like yours, teaching oneself to code would be incredibly difficult, and building a functional site (even if it lives on localhost) would be totally impossible. Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
