Unable to login with Active User having a discarded record
kashifnaseer opened this issue · 1 comments
kashifnaseer commented
Following flow is not allowing User to login, any idea, how i can resolve it
Create a New User with email like aaa@domain.com
User login works fine
Discard this aaa@domain.com user
Create an other user with aaa@domain.com
Confirm this user, confirmation works fine
now logout - login again with aaa@domain.com, It will Not work.
Here is User.rb code
class User < ActiveRecord::Base
include Discard::Model
def active_for_authentication?
super and self.active? and !discarded_at
end
def inactive_message
self.active? ? super : I18n.t("users.account_suspended")
end
end
SessionsController: Using for login
class SessionsController < Devise::SessionsController
before_action :set_encrypt_cookies, only: [:create]
def create
resource = warden.authenticate!(scope: resource_name)
set_flash_message :success, :signed_in
sign_in_and_redirect(resource_name, resource)
end
kashifnaseer commented
I fixed it by overriding devise method in user model
def self.find_for_authentication(conditions)
find_first_by_auth_conditions(conditions, discarded_at: nil)
end