Theofilos Mouratidis
Theofilos Mouratidis

Reputation: 1156

authlogic "you did not provide any details for authentication" with email and password fields in form

I constantly get the above message when I try to login to the user I created after logout...

my user model is this, name is the display name

class User < ActiveRecord::Base
  attr_accessible :name, :email, :persistence_token, :password, :password_confirmation

  before_save { |user| user.email = email.downcase }

  validates :email, uniqueness: true

  acts_as_authentic do |configuration|
    configuration.session_class = Session
  end
end

my migration is

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :email
      t.string :name
      t.string :crypted_password
      t.string :password_salt
      t.string :persistence_token
    end
  end

  def self.down
    drop_table :sessions
  end
end

and i use :email and :password fields to my login form

Upvotes: 1

Views: 1588

Answers (2)

AndrewK
AndrewK

Reputation: 1303

This is old, but for me I got this error upgrading a rails 3 to rails 4 app. In UserSession create, I had to change the

@user_session = UserSession.new(params[:user_session])

to

@user_session = UserSession.new(user_session_params)
...
private
    def user_session_params
      params.require(:user_session).permit(:email, :password)
    end

Upvotes: 3

ole
ole

Reputation: 5233

You should set login_field parameter as :email, because by default its :username or :login field:

class User < ActiveRecord::Base
  #...

  acts_as_authentic do |configuration|
    configuration.session_class = Session
    configuration.login_field = :email
  end
end

In User model you downcase email before save, so if you want to seach case insensitive email in DB, you should implement find_by_login_method:

class Session < Authlogic::Session::Base
  find_by_login_method :find_by_downcase_email
end  

class User < ActiveRecord::Base
  #...

  def self.find_by_downcase_email(login)
    find_by_email(login.downcase)
  end
end

Upvotes: 3

Related Questions