You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/lib/authentication/warden_authentication.rb

30 lines
627 B
Ruby

module WardenAuthentication
private
10 years ago
def ensure_authenticated!
warden.authenticate!(scope: warden_scope) unless warden.authenticated?(warden_scope)
end
def current_user
10 years ago
warden.authenticate(scope: warden_scope) unless warden.authenticated?(warden_scope)
warden.user(warden_scope)
end
def current_user=(user)
if user
10 years ago
warden.set_user(user, scope: warden_scope)
cookies[:auth_token] =
{ value: user.auth_token, expires: 1.year.from_now }
else
10 years ago
warden.logout(warden_scope)
cookies.delete(:auth_token)
end
end
def warden
request.env['warden']
end
end