1 <?xml version=
"1.0" encoding=
"iso-8859-1"?>
3 PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
8 <title>Class: SessionsController
</title>
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1" />
10 <meta http-equiv=
"Content-Script-Type" content=
"text/javascript" />
11 <link rel=
"stylesheet" href=
".././rdoc-style.css" type=
"text/css" media=
"screen" />
12 <script type=
"text/javascript">
15 function popupCode( url ) {
16 window.open(url,
"Code",
"resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
19 function toggleCode( id ) {
20 if ( document.getElementById )
21 elem = document.getElementById( id );
22 else if ( document.all )
23 elem = eval(
"document.all." + id );
27 elemStyle = elem.style;
29 if ( elemStyle.display !=
"block" ) {
30 elemStyle.display =
"block"
32 elemStyle.display =
"none"
38 // Make codeblocks hidden by default
39 document.writeln(
"<style type=\"text/css\
">div.method-source-code { display: none }</style>" )
49 <div id=
"classHeader">
50 <table class=
"header-table">
51 <tr class=
"top-aligned-row">
52 <td><strong>Class
</strong></td>
53 <td class=
"class-name-in-header">SessionsController
</td>
55 <tr class=
"top-aligned-row">
56 <td><strong>In:
</strong></td>
58 <a href=
"../files/app/controllers/sessions_controller_rb.html">
59 app/controllers/sessions_controller.rb
65 <tr class=
"top-aligned-row">
66 <td><strong>Parent:
</strong></td>
68 <a href=
"ApplicationController.html">
75 <!-- banner header -->
77 <div id=
"bodyContent">
81 <div id=
"contextContent">
83 <div id=
"description">
85 This controller handles the login/logout function of the site.
93 <div id=
"method-list">
94 <h3 class=
"section-bar">Methods
</h3>
96 <div class=
"name-list">
97 <a href=
"#M000009">create
</a>
98 <a href=
"#M000010">destroy
</a>
99 <a href=
"#M000008">new
</a>
117 <!-- if method_list -->
119 <h3 class=
"section-bar">Public Instance methods
</h3>
121 <div id=
"method-M000009" class=
"method-detail">
122 <a name=
"M000009"></a>
124 <div class=
"method-heading">
125 <a href=
"#M000009" class=
"method-signature">
126 <span class=
"method-name">create
</span><span class=
"method-args">()
</span>
130 <div class=
"method-description">
132 Actually log the person into the system
135 This handles verification of the user
’s credentials, along with
136 creating a cookie for Remember Me.
138 <p><a class=
"source-toggle" href=
"#"
139 onclick=
"toggleCode('M000009-source');return false;">[Source]
</a></p>
140 <div class=
"method-source-code" id=
"M000009-source">
142 <span class=
"ruby-comment cmt"># File app/controllers/sessions_controller.rb, line
12</span>
143 12:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">create
</span>
144 13:
<span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span> =
<span class=
"ruby-constant">User
</span>.
<span class=
"ruby-identifier">authenticate
</span>(
<span class=
"ruby-identifier">params
</span>[
<span class=
"ruby-identifier">:login
</span>],
<span class=
"ruby-identifier">params
</span>[
<span class=
"ruby-identifier">:password
</span>])
145 14:
<span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">logged_in?
</span>
146 15:
<span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">params
</span>[
<span class=
"ruby-identifier">:remember_me
</span>]
<span class=
"ruby-operator">==
</span> <span class=
"ruby-value str">"1"</span>
147 16:
<span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">remember_me
</span>
148 17:
<span class=
"ruby-identifier">cookies
</span>[
<span class=
"ruby-identifier">:auth_token
</span>] = {
<span class=
"ruby-identifier">:value
</span> =
<span class=
"ruby-operator">></span> <span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">remember_token
</span> ,
<span class=
"ruby-identifier">:expires
</span> =
<span class=
"ruby-operator">></span> <span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">remember_token_expires_at
</span> }
149 18:
<span class=
"ruby-keyword kw">end
</span>
150 19:
<span class=
"ruby-identifier">redirect_back_or_default
</span>(
<span class=
"ruby-value str">'/'
</span>)
151 20:
<span class=
"ruby-identifier">flash
</span>[
<span class=
"ruby-identifier">:notice
</span>] =
<span class=
"ruby-value str">"Logged in successfully
"</span>
152 21:
<span class=
"ruby-keyword kw">else
</span>
153 22:
<span class=
"ruby-identifier">render
</span> <span class=
"ruby-identifier">:action
</span> =
<span class=
"ruby-operator">></span> <span class=
"ruby-value str">'new'
</span>
154 23:
<span class=
"ruby-keyword kw">end
</span>
155 24:
<span class=
"ruby-keyword kw">end
</span>
161 <div id=
"method-M000010" class=
"method-detail">
162 <a name=
"M000010"></a>
164 <div class=
"method-heading">
165 <a href=
"#M000010" class=
"method-signature">
166 <span class=
"method-name">destroy
</span><span class=
"method-args">()
</span>
170 <div class=
"method-description">
174 <p><a class=
"source-toggle" href=
"#"
175 onclick=
"toggleCode('M000010-source');return false;">[Source]
</a></p>
176 <div class=
"method-source-code" id=
"M000010-source">
178 <span class=
"ruby-comment cmt"># File app/controllers/sessions_controller.rb, line
27</span>
179 27:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">destroy
</span>
180 28:
<span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">forget_me
</span> <span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">logged_in?
</span>
181 29:
<span class=
"ruby-identifier">cookies
</span>.
<span class=
"ruby-identifier">delete
</span> <span class=
"ruby-identifier">:auth_token
</span>
182 30:
<span class=
"ruby-identifier">reset_session
</span>
183 31:
<span class=
"ruby-identifier">flash
</span>[
<span class=
"ruby-identifier">:notice
</span>] =
<span class=
"ruby-value str">"You have been logged out.
"</span>
184 32:
<span class=
"ruby-identifier">redirect_back_or_default
</span>(
<span class=
"ruby-value str">'/'
</span>)
185 33:
<span class=
"ruby-keyword kw">end
</span>
191 <div id=
"method-M000008" class=
"method-detail">
192 <a name=
"M000008"></a>
194 <div class=
"method-heading">
195 <a href=
"#M000008" class=
"method-signature">
196 <span class=
"method-name">new
</span><span class=
"method-args">()
</span>
200 <div class=
"method-description">
202 This is the login form page
204 <p><a class=
"source-toggle" href=
"#"
205 onclick=
"toggleCode('M000008-source');return false;">[Source]
</a></p>
206 <div class=
"method-source-code" id=
"M000008-source">
208 <span class=
"ruby-comment cmt"># File app/controllers/sessions_controller.rb, line
6</span>
209 6:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">new
</span>;
<span class=
"ruby-keyword kw">end
</span>
222 <div id=
"validator-badges">
223 <p><small><a href=
"http://validator.w3.org/check/referer">[Validate]
</a></small></p>