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.
26 lines
433 B
Ruby
26 lines
433 B
Ruby
11 years ago
|
module WardenAuthentication
|
||
|
|
||
|
private
|
||
|
|
||
|
def current_user
|
||
|
warden.authenticate(:auth_cookie) unless warden.authenticated?
|
||
|
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
|
||
|
|
||
|
end
|