asciinema.org/lib/authentication/warden_authentication.rb

30 lines
500 B
Ruby
Raw Normal View History

2014-02-20 22:00:44 +00:00
module WardenAuthentication
private
def current_user
2014-03-16 15:03:33 +00:00
warden.authenticate(*warden_strategies) unless warden.authenticated?
2014-02-20 22:00:44 +00:00
warden.user
end
def current_user=(user)
if user
warden.set_user(user)
cookies[:auth_token] =
{ value: user.auth_token, expires: 1.year.from_now }
else
warden.logout
cookies.delete(:auth_token)
end
end
def warden
request.env['warden']
end
2014-03-16 15:03:33 +00:00
def warden_strategies
raise NotImplementedError
end
2014-02-20 22:00:44 +00:00
end