Skip to content
Browse files

add password reset, ripped straight from http://www.binarylogic.com/2…

…008/11/16/tutorial-reset-passwords-with-authlogic/, get rid of layout calls and use default instead. add tests for resetting passwords.

Signed-off-by: Austin On Rails <github-austinonrails@damon.otherinbox.com>
  • Loading branch information...
1 parent 83de002 commit a9ea74be6efa12b737b5d8431e836ef05365558a @robrasmussen robrasmussen committed with Austin On Rails Apr 23, 2009
View
4 app/controllers/application.rb
@@ -29,8 +29,8 @@ def require_member
def require_no_member
if current_member
store_location
- flash[:notice] = "You must be logged out to access this page"
- redirect_to account_url
+ flash[:notice] = "You must be logged out to access the requested page"
+ redirect_to root_url
return false
end
end
View
2 app/controllers/member_interests_controller.rb
@@ -1,8 +1,6 @@
class MemberInterestsController < ApplicationController
before_filter :require_member, :only => [ :create ]
- layout "members"
-
def index
@topic = Topic.find(params[:topic_id])
@members = @topic.enthusiasts
View
2 app/controllers/member_sessions_controller.rb
@@ -1,7 +1,5 @@
class MemberSessionsController < ApplicationController
- layout 'members'
-
before_filter :require_no_member, :only => [:new, :create]
before_filter :require_member, :only => :destroy
View
2 app/controllers/topics_controller.rb
@@ -2,8 +2,6 @@ class TopicsController < ApplicationController
before_filter :require_member, :only => [ :new, :create, :edit, :update, :destroy ]
helper :members
-
- layout "members"
def index
@topics = Topic.find(:all, :order => "interest_count desc").paginate(:page => params[:page], :per_page => 10)
View
5 app/models/member.rb
@@ -37,4 +37,9 @@ def interested_in?(topic)
def will_speak_on?(topic)
self.presentations.exists?(topic)
end
+
+ def deliver_password_reset_instructions!
+ reset_perishable_token!
+ Notifier.deliver_password_reset_instructions(self)
+ end
end
View
85 app/views/layouts/members.rhtml
@@ -1,85 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>Austin On Rails | Austin's Official Ruby on Rails User Group</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="author" content="Jamie Hill" />
- <title>Members: <%= controller.action_name %></title>
- <%= javascript_include_tag :defaults %>
- <%= javascript_include_tag 'typo', 'lucid', 'cookies' %>
- <%= stylesheet_link_tag 'master', 'color', 'member', :media => 'screen' %>
- <%= stylesheet_link_tag 'print', :media => 'print' %>
-</head>
-<body class="c-ms cs2 fixed">
-<div id="wrapper"><div id="w2"><div id="w3" class="clearfix">
-<div id="header" class="clearfix">
- <div id="logo">
- <h1><%= link_to "Austin on Rails", "http://www.austinonrails.org" %></h1>
- <h2><%= link_to "Member Directory", :controller => 'members' %> | <%= link_to "Topics List", :controller => 'topics' %></h2>
- </div>
- <div id="search">
-
- </div>
- <ul id="preferences">
- <li><a href="javascript:;" id="layout-options" title="Layout and color options">Layout and color options</a></li>
- <li><a href="javascript:;" id="layout-fixed" title="Switch to fixed layout">Fixed</a></li>
- <li><a href="javascript:;" id="layout-fluid" title="Switch to fluid layout">Fluid</a></li>
-
- </ul>
- <div id="theme-panel" style="display:none;">
- <ul>
- <li><a href="javascript:;" id="cs0_swatch" title="Ruby color set">Ruby color set</a></li>
- <li><a href="javascript:;" id="cs1_swatch" title="Mint color set">Mint color set</a></li>
- <li><a href="javascript:;" id="cs2_swatch" title="Bleached color set">Bleached color set</a></li>
- </ul>
-
- </div></div>
-<div id="content">
-<div id="maincol"><div id="mc2">
-<div class="post">
-<%= yield %>
-</div>
-</div></div> <!-- end #maincol -->
-
-<div id="subcol">
- <div class="bt"><div></div></div>
- <div id="sc2">
- <div class="sidebar-node">
- <h3>Navigation</h3>
- <ul>
- <li><%= link_to 'Member Listing', list_members_path %></li>
- <li><%= link_to 'Topic Listing', topics_path %></li>
-
- <% if current_member %>
- <li><%= link_to 'Edit your profile', edit_member_path(current_member.id) %></li>
- <li><%= link_to "Logout", logout_path %></li>
-
- <% else %>
- <li><%= link_to 'Create a new profile', :controller => 'members', :action => 'new' %></li>
- <li><%= link_to 'Login', login_path %></li>
- <% end %>
- </ul>
- </div>
- <%= yield :sidebar %>
- </div>
-</div> <!-- end #subcol -->
-
-</div> <!-- end #content -->
-
-<div id="subfoot">
- <div class="bb"><div></div></div>
-</div>
-
-<div id="footer">
- <p>
- <a href="http://validator.w3.org/check/referer" title="Validates this page">XHTML</a>,
- <a href="http://jigsaw.w3.org/css-validator/check/referer?warning=no&amp;profile=css2" title="Validates the CSS on this page.">CSS</a>.
- Template by <a href="http://www.soniciq.com" title="SonicIQ - Website Development">SonicIQ</a>.
- </p>
-
-</div>
-
-</div></div></div> <!-- end #wrapper -->
-
-</body>
-</html>
View
2 app/views/member_sessions/new.html.erb
@@ -10,7 +10,7 @@
<p><label for="member_password" class="req">Password</label>
<%= password_field "member", "password"%></p>
- <p class="btn"><%= submit_tag "Login" %></p>
+ <p class="btn"><%= submit_tag "Login" %> <%= link_to "Reset my password", new_password_reset_path %></p>
</div><% end %>
</div> <!-- end .post-body --><%#
# To change this template, choose Tools | Templates
View
4 app/views/members/list.rhtml
@@ -4,7 +4,9 @@
:locals => {"heading_text" => "Member Listing", "sub_heading_text" => "Show all members, most recent first."}) %>
-
+<% if flash[:notice] %>
+ <h3><%= flash[:notice] %></h3>
+<% end %>
<div class="post-body">
<%= content_tag("p", flash[:welcome]) if flash[:welcome] %>
<%= "<p>Members who are #{@occupation.name.downcase.pluralize}&nbsp;" + (link_to "(Show all)", :action => :list) + "</p>" if @occupation %>
View
6 config/routes.rb
@@ -6,8 +6,10 @@
:member => {:enthusiasts => :get, :experts => :get,
:speakers => :get, :auto_complete_for_topic_name => :get} do |topic|
- topic.resources :interests, :controller => "MemberInterests"
- end
+ topic.resources :interests, :controller => "MemberInterests"
+ end
+
+ map.resources :password_resets
# Add your own custom routes here.
# The priority is based upon order of creation: first created -> highest priority.
View
8 test/fixtures/members.yml
@@ -9,7 +9,7 @@ first_programmer:
persistence_token: foo
crypted_password: bc2c5774c00961030d2545155db2188289f56ee9660343a0e7e0aea87dfdb0461cf6867142377c5a67b3403ef631bb5cedf682ea733d0eaf622b1a312d0b3428
password_salt: 870192c8b7b2d963efa95e2c3d1538f14f6d37dd72cb5f03cad115e9f3ab127d3df23a3f6baf7cf1bee6807c6344a315bc3a2c47e7d1eeeb3b77bf66e601b989
-
+ perishable_token: ""
second_programmer:
id: 2
first_name: Second
@@ -19,7 +19,7 @@ second_programmer:
occupation_id: 1
crypted_password: bc2c5774c00961030d2545155db2188289f56ee9660343a0e7e0aea87dfdb0461cf6867142377c5a67b3403ef631bb5cedf682ea733d0eaf622b1a312d0b3428
password_salt: 870192c8b7b2d963efa95e2c3d1538f14f6d37dd72cb5f03cad115e9f3ab127d3df23a3f6baf7cf1bee6807c6344a315bc3a2c47e7d1eeeb3b77bf66e601b989
-
+ perishable_token: ""
first_designer:
id: 3
first_name: Edward
@@ -28,7 +28,7 @@ first_designer:
occupation_id: 2
crypted_password: bc2c5774c00961030d2545155db2188289f56ee9660343a0e7e0aea87dfdb0461cf6867142377c5a67b3403ef631bb5cedf682ea733d0eaf622b1a312d0b3428
password_salt: 870192c8b7b2d963efa95e2c3d1538f14f6d37dd72cb5f03cad115e9f3ab127d3df23a3f6baf7cf1bee6807c6344a315bc3a2c47e7d1eeeb3b77bf66e601b989
-
+ perishable_token: ""
no_occupation:
id: 4
first_name: No
@@ -37,6 +37,6 @@ no_occupation:
is_email_visible: false
crypted_password: bc2c5774c00961030d2545155db2188289f56ee9660343a0e7e0aea87dfdb0461cf6867142377c5a67b3403ef631bb5cedf682ea733d0eaf622b1a312d0b3428
password_salt: 870192c8b7b2d963efa95e2c3d1538f14f6d37dd72cb5f03cad115e9f3ab127d3df23a3f6baf7cf1bee6807c6344a315bc3a2c47e7d1eeeb3b77bf66e601b989
-
+ perishable_token: ""
View
1 test/functional/members_controller_test.rb
@@ -86,7 +86,6 @@ def test_updating_other_user_redirects_to_login
Member.any_instance.expects(:spam?).returns(false)
login members(:first_programmer)
post :update, :member => members(:first_programmer).attributes.merge(:id => members(:second_programmer).id)
-
assert_redirected_to :action => "index"
#insure nothing changed
View
1 test/test_helper.rb
@@ -37,6 +37,7 @@ def assert_login_needed
def login(member)
set_session_for(member)
+ member.reset_perishable_token!
end
def assert_email_not_shown(for_user)

0 comments on commit a9ea74b

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