discourse/lib/current_user.rb

48 lines
1003 B
Ruby
Raw Normal View History

2013-02-05 13:16:51 -06:00
module CurrentUser
def self.has_auth_cookie?(env)
Discourse.current_user_provider.new(env).has_auth_cookie?
end
2013-02-15 02:23:40 -06:00
def self.lookup_from_env(env)
Discourse.current_user_provider.new(env).current_user
end
# can be used to pretend current user does no exist, for CSRF attacks
def clear_current_user
@current_user_provider = Discourse.current_user_provider.new({})
end
def log_on_user(user)
2017-07-27 20:20:09 -05:00
current_user_provider.log_on_user(user, session, cookies)
user.logged_in
end
def log_off_user
2017-07-27 20:20:09 -05:00
current_user_provider.log_off_user(session, cookies)
2013-02-15 02:23:40 -06:00
end
def is_api?
current_user_provider.is_api?
end
def is_user_api?
current_user_provider.is_user_api?
end
2013-02-05 13:16:51 -06:00
def current_user
current_user_provider.current_user
end
2013-03-25 20:04:28 -05:00
def refresh_session(user)
2017-07-27 20:20:09 -05:00
current_user_provider.refresh_session(user, session, cookies)
end
private
2013-03-25 20:04:28 -05:00
def current_user_provider
@current_user_provider ||= Discourse.current_user_provider.new(request.env)
2013-02-05 13:16:51 -06:00
end
end