Ruby on Rails - Sorcery override login method

336 Views Asked by At

I have a user table with guest column(boolean) to distinguish user's identity. I don't want user with guest? => true able to login. Is it possible to override Sorcery's login method?

I want it work like User.where(guest: false).authenticate(email, password)

Another way I'm thinking is to separate User and GuestUser using polymorphic association. However, I don't really want to create GuestUser with same columns as User.

Please give me some suggestions.

1

There are 1 best solutions below

0
7urkm3n On BEST ANSWER
  # find specific user and check guest or not
  user = User.find_by_email(email)
  if user && user.guest == false
     User.authenticate(email, password)
  end