Permalink
Browse files

Fixed a bug regarding capitalized / uncapitalized emails.

  • Loading branch information...
1 parent 4a1b5aa commit 3c72b8e921025a705e87f1a9712918e98dda64d8 @ptierney committed Nov 15, 2011
Showing with 21 additions and 4 deletions.
  1. +7 −2 app/controllers/password_reset_controller.rb
  2. +14 −2 app/models/user.rb
@@ -5,8 +5,13 @@ def new
def create
email = params[:password_reset][:email]
- flash[:success] = "Reset email sent to #{email}";
- User.forgot_password(email)
+
+ if User.forgot_password(email)
+ flash[:success] = "Reset email sent to #{email}"
+ else
+ flash[:error] = "Unable to reset password for #{email}. Please check that it is correct."
+ end
+
redirect_to root_path
end
View
@@ -50,7 +50,7 @@ def has_password?(submitted_password)
end
def self.authenticate(email, submitted_password)
- user = find_by_email(email)
+ user = User.find_by_email_insensitive(email)
return nil if user.nil?
return user if user.has_password?(submitted_password)
end
@@ -87,11 +87,13 @@ def secure_hash(string)
# assign them a random one and mail it to them, asking them to change it
def self.forgot_password(user_email)
- @user = User.find_by_email(user_email)
+ @user = User.find_by_email_insensitive(user_email)
+ return false unless @user
random_password = Array.new(10).map { (65 + rand(58)).chr }.join
@user.password = random_password
@user.save!
Notifier.password_change(@user, random_password).deliver
+ return true
end
def has_valid_code
@@ -106,4 +108,14 @@ def has_valid_code
return true
end
+ def self.find_by_email_insensitive(em)
+ User.all.each do |u|
+ if u.email.downcase == em.downcase
+ return u
+ end
+ end
+
+ return nil
+ end
+
end

0 comments on commit 3c72b8e

Please sign in to comment.