asciinema.org/lib/authentication/warden_authentication.rb

30 lines
667 B
Ruby
Raw Normal View History

2014-02-20 22:00:44 +00:00
module WardenAuthentication
private
2015-04-04 17:46:55 +00:00
def ensure_authenticated!
warden.authenticate!(*warden_strategies, scope: warden_scope) unless warden.authenticated?(warden_scope)
2015-04-04 17:46:55 +00:00
end
2014-02-20 22:00:44 +00:00
def current_user
warden.authenticate(*warden_strategies, scope: warden_scope) unless warden.authenticated?(warden_scope)
2015-04-04 17:46:55 +00:00
warden.user(warden_scope)
2014-02-20 22:00:44 +00:00
end
def current_user=(user)
if user
2015-04-04 17:46:55 +00:00
warden.set_user(user, scope: warden_scope)
2014-02-20 22:00:44 +00:00
cookies[:auth_token] =
{ value: user.auth_token, expires: 1.year.from_now }
else
2015-04-04 17:46:55 +00:00
warden.logout(warden_scope)
2014-02-20 22:00:44 +00:00
cookies.delete(:auth_token)
end
end
def warden
request.env['warden']
end
end