Devise Authentication unscoped
At Shop2 we do the Rails 3.2, Mongoid 2.4, and Devise 2.0. We found that Devise by default does not play nice with default scoping.
Our User model with default_scope of active users,
and a :vip scope
class User
include Mongoid::Document
field :status
now only active users can be authenticated
default_scope where(status: 'active')
scope :vip, where(status: 'vip')
end
So how would we authenticate VIPs?
Devise uses Warden::Strategies to authenticate, and loads back user from a session. This is how I plugged into Devise:
lib/vip_authenticatable.rb
We introduce :vip_authenticatable strategy to Warden.
With this strategy your login form might look something like
<form action="/path/to/create/session">
<input name="vip[:id]" placeholder="Enter your VIP No.">
<input type="submit">
</form>
Warden::Strategies.add(:vip_authenticatable) do
def valid?
...