I am using active_for_authentication? to allow only active users to login through devise. But it's not working.
My controller:
class DashboardUsersController < ApplicationController
def active_for_authentication?
super && self.deactivated_ind
end
def inactive_message
"Sorry, this account has been deactivated."
end
My model:
class DashboardUser < ActiveRecord::Base
devise :database_authenticatable,:rememberable, :trackable, :validatable, :timeoutable
attr_accessor :login
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["username = :value OR lower(email) = lower(:value)", { :value => login }]).first
else
where(conditions).first
end
end
end
My user table:
t.string "deactivated_ind", limit: 1
t.date "deactivated_date"
By using deactivated_ind Y / N i check user is active / inactive. Now i want allow devise to log in only those user have N in deactivated_ind colomn
active_for_authentication? needs to be a method on a model, not on a controller
(not a problem in your case, but was mine) active_for_authentication? must be a public method on a model
Part of the problem, I'm guessing is that you're using a string for "deactivated_ind" instead of a boolean. A string of "N" and a string of "Y" will both be true when you try to use them as boolean values, since neither is nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With