Skip to content

Instantly share code, notes, and snippets.

@khoan
Created July 20, 2012 02:35
Show Gist options
  • Save khoan/3148302 to your computer and use it in GitHub Desktop.
Save khoan/3148302 to your computer and use it in GitHub Desktop.
Devise Authentication unscoped
# 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?
params[:vip] && params[:vip][:id]
end
def authenticate!
vip = User.vip.find(params[:vip][:id])
if vip
success! vip
elsif !halted?
fail! :invalid
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment