Created
July 20, 2012 02:35
-
-
Save khoan/3148302 to your computer and use it in GitHub Desktop.
Devise Authentication unscoped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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