Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Mongoid part 2

  • Loading branch information...
commit f44ab2e1e3e6311ac09aab2e99f156ce4c7c4a1e 1 parent 6f1c2b0
Elad Meidar authored March 07, 2010
3  _site/2010/03/creating-a-rails-authentication-system-on-mongoid-part-2-7-3-2010/index.html
@@ -66,6 +66,7 @@ <h3 class="post_title"><a href="/2010/03/creating-a-rails-authentication-system-
66 66
 <p>The first thing we need to do to allow a login from cookie, is to get our User model familiar with some new fields and methods to make that process possible.</p>
67 67
 <p>First, we need to add a few fields to our user document and a add a few methods to instance and class, this is our new <code>User.rb</code>:</p>
68 68
 <h5>User.rb changes</h5>
  69
+<p>We changed <code>User.rb</code> a bit:</p>
69 70
 <script src="http://gist.github.com/324635.js?file=User.rb"></script><p>We <strong>added 2 fields</strong>, <code>remember_token_expires_at</code> and <code>remember_token</code>, both to keep a token and and an expiry limit.<br />
70 71
 We also added the following instance methods:</p>
71 72
 <ul>
@@ -83,7 +84,7 @@ <h3 class="post_title"><a href="/2010/03/creating-a-rails-authentication-system-
83 84
 <h5>ApplicationController changes</h5>
84 85
 <p>In the end of Part 1, i gave an example to some methods that should be on <code>application_controller</code> in order to make the session management and the entire authentication process easier. Since those were just examples and were meant barely to support basic usage, we will need to go through it a bit more seriously and create a more precise and smart <code>application_controller</code>.</p>
85 86
 <p>In this case, we can simply grab all the methods from Restful Authentication&#8217;s <code>authentication.rb</code> module, and weld it to our <code>application_controller</code>:</p>
86  
-<script src="http://gist.github.com/324641.js?file=application_controller.rb"></script><p>we added a few methods and changed a few existing ones, this is pretty straight forward and basically a 1:1 copy from Restful Authentication, the only important thing to really pay attention to are the <code>current_user</code> and the <code>current_user=</code> which are different than what we had in my previous example and now take more into consideration (cookies and HTTPauth for example.)</p>
  87
+<script src="http://gist.github.com/324641.js?file=application_controller.rb"></script><p>we added a few methods and changed a few existing ones, this is pretty straight forward and basically a 1:1 copy from Restful Authentication, the only important thing to really pay attention to are the <code>current_user</code> and the <code>current_user=</code> which are different than what we had in my previous example and now takes more into consideration (cookies and HTTPauth for example.)</p>
87 88
 <p>Since now we have a getter for <code>current_user</code> we need to change our <code>sessions_controller</code> too.</p>
88 89
 <h5>SessionsController changes</h5>
89 90
 <p>This is our current <code>sessions_controller</code>:</p>
5  _site/feed/atom.xml
@@ -4,7 +4,7 @@
4 4
  <title>Emphasized Insanity</title>
5 5
  <link href="http://blog.eizesus.com/feed/atom.xml" rel="self"/>
6 6
  <link href="http://blog.eizesus.com/"/>
7  
- <updated>2010-03-07T18:35:01-05:00</updated>
  7
+ <updated>2010-03-07T18:37:56-05:00</updated>
8 8
  <id>http://blog.eizesus.com/</id>
9 9
  <author>
10 10
    <name>Elad Meidar</name>
@@ -25,6 +25,7 @@
25 25
 &lt;p&gt;The first thing we need to do to allow a login from cookie, is to get our User model familiar with some new fields and methods to make that process possible.&lt;/p&gt;
26 26
 &lt;p&gt;First, we need to add a few fields to our user document and a add a few methods to instance and class, this is our new &lt;code&gt;User.rb&lt;/code&gt;:&lt;/p&gt;
27 27
 &lt;h5&gt;User.rb changes&lt;/h5&gt;
  28
+&lt;p&gt;We changed &lt;code&gt;User.rb&lt;/code&gt; a bit:&lt;/p&gt;
28 29
 &lt;script src=&quot;http://gist.github.com/324635.js?file=User.rb&quot;&gt;&lt;/script&gt;&lt;p&gt;We &lt;strong&gt;added 2 fields&lt;/strong&gt;, &lt;code&gt;remember_token_expires_at&lt;/code&gt; and &lt;code&gt;remember_token&lt;/code&gt;, both to keep a token and and an expiry limit.&lt;br /&gt;
29 30
 We also added the following instance methods:&lt;/p&gt;
30 31
 &lt;ul&gt;
@@ -42,7 +43,7 @@ We also added the following instance methods:&lt;/p&gt;
42 43
 &lt;h5&gt;ApplicationController changes&lt;/h5&gt;
43 44
 &lt;p&gt;In the end of Part 1, i gave an example to some methods that should be on &lt;code&gt;application_controller&lt;/code&gt; in order to make the session management and the entire authentication process easier. Since those were just examples and were meant barely to support basic usage, we will need to go through it a bit more seriously and create a more precise and smart &lt;code&gt;application_controller&lt;/code&gt;.&lt;/p&gt;
44 45
 &lt;p&gt;In this case, we can simply grab all the methods from Restful Authentication&amp;#8217;s &lt;code&gt;authentication.rb&lt;/code&gt; module, and weld it to our &lt;code&gt;application_controller&lt;/code&gt;:&lt;/p&gt;
45  
-&lt;script src=&quot;http://gist.github.com/324641.js?file=application_controller.rb&quot;&gt;&lt;/script&gt;&lt;p&gt;we added a few methods and changed a few existing ones, this is pretty straight forward and basically a 1:1 copy from Restful Authentication, the only important thing to really pay attention to are the &lt;code&gt;current_user&lt;/code&gt; and the &lt;code&gt;current_user=&lt;/code&gt; which are different than what we had in my previous example and now take more into consideration (cookies and HTTPauth for example.)&lt;/p&gt;
  46
+&lt;script src=&quot;http://gist.github.com/324641.js?file=application_controller.rb&quot;&gt;&lt;/script&gt;&lt;p&gt;we added a few methods and changed a few existing ones, this is pretty straight forward and basically a 1:1 copy from Restful Authentication, the only important thing to really pay attention to are the &lt;code&gt;current_user&lt;/code&gt; and the &lt;code&gt;current_user=&lt;/code&gt; which are different than what we had in my previous example and now takes more into consideration (cookies and HTTPauth for example.)&lt;/p&gt;
46 47
 &lt;p&gt;Since now we have a getter for &lt;code&gt;current_user&lt;/code&gt; we need to change our &lt;code&gt;sessions_controller&lt;/code&gt; too.&lt;/p&gt;
47 48
 &lt;h5&gt;SessionsController changes&lt;/h5&gt;
48 49
 &lt;p&gt;This is our current &lt;code&gt;sessions_controller&lt;/code&gt;:&lt;/p&gt;

0 notes on commit f44ab2e

Please sign in to comment.
Something went wrong with that request. Please try again.