Skip to content

Commit

Permalink
references #57
Browse files Browse the repository at this point in the history
  • Loading branch information
lynndylanhurley committed Oct 30, 2014
1 parent a478bd5 commit 0e39e9e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
11 changes: 7 additions & 4 deletions app/controllers/devise_token_auth/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ def create
email = resource_params[:email]
end

@resource = resource_class.where({
email: email,
provider: 'email'
}).first
q = "uid='#{email}' AND provider='email'"

if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql'
q = "BINARY uid='#{email}' AND provider='email'"
end

@resource = resource_class.where(q).first

errors = nil

Expand Down
9 changes: 8 additions & 1 deletion app/controllers/devise_token_auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ def create
else
email = resource_params[:email]
end
@resource = resource_class.find_by_email(email)

q = "uid='#{email}' AND provider='email'"

if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql'
q = "BINARY uid='#{email}' AND provider='email'"
end

@resource = resource_class.where(q).first

if @resource and valid_params? and @resource.valid_password?(resource_params[:password]) and @resource.confirmed?
# create client id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
end

describe 'case-insensitive email' do

before do
@resource_class = User
@request_params = {
Expand All @@ -129,9 +128,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
xhr :post, :create, @request_params
assert_equal 400, response.status
end

end

end

describe "change password" do
Expand Down
24 changes: 12 additions & 12 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
t.datetime "updated_at"
end

add_index "evil_users", ["confirmation_token"], name: "index_evil_users_on_confirmation_token", unique: true
add_index "evil_users", ["email"], name: "index_evil_users_on_email"
add_index "evil_users", ["reset_password_token"], name: "index_evil_users_on_reset_password_token", unique: true
add_index "evil_users", ["uid", "provider"], name: "index_evil_users_on_uid_and_provider", unique: true
add_index "evil_users", ["confirmation_token"], name: "index_evil_users_on_confirmation_token", unique: true, using: :btree
add_index "evil_users", ["email"], name: "index_evil_users_on_email", using: :btree
add_index "evil_users", ["reset_password_token"], name: "index_evil_users_on_reset_password_token", unique: true, using: :btree
add_index "evil_users", ["uid", "provider"], name: "index_evil_users_on_uid_and_provider", unique: true, using: :btree

create_table "mangs", force: true do |t|
t.string "email"
Expand Down Expand Up @@ -72,10 +72,10 @@
t.string "favorite_color"
end

add_index "mangs", ["confirmation_token"], name: "index_mangs_on_confirmation_token", unique: true
add_index "mangs", ["email"], name: "index_mangs_on_email"
add_index "mangs", ["reset_password_token"], name: "index_mangs_on_reset_password_token", unique: true
add_index "mangs", ["uid", "provider"], name: "index_mangs_on_uid_and_provider", unique: true
add_index "mangs", ["confirmation_token"], name: "index_mangs_on_confirmation_token", unique: true, using: :btree
add_index "mangs", ["email"], name: "index_mangs_on_email", using: :btree
add_index "mangs", ["reset_password_token"], name: "index_mangs_on_reset_password_token", unique: true, using: :btree
add_index "mangs", ["uid", "provider"], name: "index_mangs_on_uid_and_provider", unique: true, using: :btree

create_table "users", force: true do |t|
t.string "email"
Expand Down Expand Up @@ -106,9 +106,9 @@
t.string "favorite_color"
end

add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
add_index "users", ["email"], name: "index_users_on_email"
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
add_index "users", ["email"], name: "index_users_on_email", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree

end

0 comments on commit 0e39e9e

Please sign in to comment.