Skip to content

e-mail should be case insensitive on password reset #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.mdown

This file was deleted.

3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This app follows the reset passwords tutorial: [http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic](http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic)

For more information on the app itself please see the {master branch}[http://github.com/binarylogic/authlogic_example/tree/master]
2 changes: 1 addition & 1 deletion app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def new
end

def create
@user = User.find_by_email(params[:email])
@user = User.where("LOWER(email) = ?", params[:email]).first
if @user
@user.deliver_password_reset_instructions!
flash[:notice] = "Instructions to reset your password have been emailed to you. " +
Expand Down
20 changes: 5 additions & 15 deletions app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ def new

def create
@user_session = UserSession.new(params[:user_session])
# We are saving with a block to accomodate for OpenID authentication
# If you are not using OpenID you can save without a block:
#
# if @user_session.save
# # ... successful login
# else
# # ... unsuccessful login
# end
@user_session.save do |result|
if result
flash[:notice] = "Login successful!"
redirect_back_or_default account_url
else
render :action => :new
end
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default account_url
else
render :action => :new
end
end

Expand Down
22 changes: 1 addition & 21 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
class User < ActiveRecord::Base
# ALL of the following code is for OpenID integration. If you are not using OpenID in your app
# just remove all of the following code, to the point where you User class is completely blank.
acts_as_authentic :login_field_validation_options => {:if => :openid_identifier_blank?}, :password_field_validation_options => {:if => :openid_identifier_blank?}

validate :normalize_openid_identifier
validates_uniqueness_of :openid_identifier, :allow_blank => true
validates_length_of :email, :minimum => 500, :unless => "true"

# For acts_as_authentic configuration
def openid_identifier_blank?
openid_identifier.blank?
end
acts_as_authentic

def deliver_password_reset_instructions!
reset_perishable_token!
Notifier.deliver_password_reset_instructions(self)
end

private
def normalize_openid_identifier
begin
self.openid_identifier = OpenIdAuthentication.normalize_url(openid_identifier) if !openid_identifier.blank?
rescue OpenIdAuthentication::InvalidOpenId => e
errors.add(:openid_identifier, e.message)
end
end
end
34 changes: 0 additions & 34 deletions app/models/user_session.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,2 @@
class UserSession < Authlogic::Session::Base
# ALL of the following code is for OpenID integration. If you are not using OpenID in your app
# just remove all of the following code, to the point where you UserSession class is completely blank.
attr_accessor :openid_identifier

def authenticating_with_openid?
!openid_identifier.blank? || controller.params[:open_id_complete]
end

def save(&block)
if authenticating_with_openid?
raise ArgumentError.new("You must supply a block to authenticate with OpenID") unless block_given?

controller.send(:authenticate_with_open_id, openid_identifier) do |result, openid_identifier|
if !result.successful?
errors.add_to_base(result.message)
yield false
return
end

record = klass.find_by_openid_identifier(openid_identifier)

if !record
errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?")
yield false
return
end

self.unauthorized_record = record
super
end
else
super
end
end
end
22 changes: 5 additions & 17 deletions app/views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@

<% form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
<div id="login_container"<% unless @user_session.openid_identifier.blank? %> style="display: none;"<% end %>>
<%= f.label :login %> (or <%= link_to_function "login using OpenID", "$('login_container').toggle(); $('openid_container').toggle();" %>)<br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
</div>
<!--
Notice the following is for OpenID. If you are not implementing OpenID in your app, simply remove the following <div> block.
Also, notice the <div id="login_container"> above, those fields do not need to be wrapped in a <div>, you can remove that as well.
I apologize if this makes it a little confusing, I have been building this app with a number of tutorials and one of them has been
OpenID integration.
-->
<div id="openid_container"<% if @user_session.openid_identifier.blank? %> style="display: none;"<% end %>>
<%= f.label :openid_identifier, "OpenID" %> (or <%= link_to_function "login using a standard username / password", "$('login_container').toggle(); $('openid_container').toggle();" %>)<br /><br />
<%= f.text_field :openid_identifier %><br />
</div>
<%= f.label :login %><br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<br />
<%= f.check_box :remember_me %><%= f.label :remember_me %><br />
<br />
Expand Down
7 changes: 0 additions & 7 deletions app/views/users/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
<%= form.label :password_confirmation %><br />
<%= form.password_field :password_confirmation %><br />
<br />
<!--
The following is for OpenID integration, if you are not using OpenID in your app
simple remove the :openid_identifier label and field
-->
<%= form.label :openid_identifier, "Or use OpenID instead of a standard login / password" %><br />
<%= form.text_field :openid_identifier %><br />
<br />
<%= form.label :email %><br />
<%= form.text_field :email %><br />
<br />
20 changes: 5 additions & 15 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<!--
The following is for OpenID, if you are not using OpenID in your app remove
the OpenID if statement and field below.
-->
<% if @user.openid_identifier.blank? %>
<p>
<b>Login:</b>
<%=h @user.login %>
</p>
<% else %>
<p>
<b>OpenID:</b>
<%=h @user.openid_identifier %>
</p>
<% end %>
<p>
<b>Login:</b>
<%=h @user.login %>
</p>

<p>
<b>Email:</b>
<%=h @user.email %>
Expand Down
19 changes: 0 additions & 19 deletions db/migrate/20081119233359_add_users_openid_field.rb

This file was deleted.

20 changes: 0 additions & 20 deletions db/migrate/20081120163933_create_openid_tables.rb

This file was deleted.

35 changes: 0 additions & 35 deletions vendor/plugins/open_id_authentication/CHANGELOG

This file was deleted.

Loading