'Devise - Rails 4 - Not able to login

I just started using Rails 4. I got devise setup with custom fields. I'm able to login after I register, but I'm not able to login from the login page. The user registration goes in fine, and I have username, password etc in the database table.

Can somebody tell me what I'm missing? My User model is very basic. Here is how it looks like -

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :username, :uniqueness => true, :presence => {:message => '- Username cannot be blank'}
  validates :first_name, :presence => { :message => " - Firstname cannot be blank!"}    

  private
    def user_params
        params.require().permit(:first_name, :last_name, :username, :email, :password, :password_confirmation)
    end
end

I've checked my view and I'm passing the right parameters.

I have the following in my application controller -

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  layout :layout_by_resource

  before_filter :configure_permitted_params, if: :devise_controller?

  def layout_by_resource
    if devise_controller?
        "devise"
    else
        "application"       
    end
  end

  protected

  def configure_permitted_params
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username, :first_name, :last_name, :password, :password_confirmation, :email) }
  end

end

I checked the database table and I do have username and password (encrypted_password that is). I have my authentication keys set to username.

Not sure what I'm missing here. I have devise 3.0.0



Solution 1:[1]

I was using devise confirmable. devise.rb was setup in such a way that it wouldn't let me log in if the account's email wasn't confirmed. So what worked in my case was adding the following flag in devise.rb config.allow_unconfirmed_access_for = 999.days

Default value is nil which means devise won't let you login until the user has confirmed their email

In my UI I show a error message bar that has a button to trigger resending of confirmation mail. The error bar stays until the user has confirmed their mail.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Surbhit Rao