2013-02-05 14:16:51 -05:00
|
|
|
module CurrentUser
|
|
|
|
|
2013-04-11 02:24:08 -04:00
|
|
|
def self.has_auth_cookie?(env)
|
2013-10-09 00:10:37 -04:00
|
|
|
Discourse.current_user_provider.new(env).has_auth_cookie?
|
2013-04-11 02:24:08 -04:00
|
|
|
end
|
|
|
|
|
2013-02-15 03:23:40 -05:00
|
|
|
def self.lookup_from_env(env)
|
2013-10-09 00:10:37 -04:00
|
|
|
Discourse.current_user_provider.new(env).current_user
|
2013-02-24 05:42:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-07-29 01:13:13 -04:00
|
|
|
# can be used to pretend current user does no exist, for CSRF attacks
|
|
|
|
def clear_current_user
|
2013-10-09 00:10:37 -04:00
|
|
|
@current_user_provider = Discourse.current_user_provider.new({})
|
2013-07-29 01:13:13 -04:00
|
|
|
end
|
|
|
|
|
2013-02-24 05:42:04 -05:00
|
|
|
def log_on_user(user)
|
2013-10-09 00:10:37 -04:00
|
|
|
current_user_provider.log_on_user(user,session,cookies)
|
2013-02-24 05:50:34 -05:00
|
|
|
end
|
|
|
|
|
2013-10-09 00:10:37 -04:00
|
|
|
def log_off_user
|
|
|
|
current_user_provider.log_off_user(session,cookies)
|
2013-02-15 03:23:40 -05:00
|
|
|
end
|
|
|
|
|
2013-07-29 01:13:13 -04:00
|
|
|
def is_api?
|
2013-10-09 00:10:37 -04:00
|
|
|
current_user_provider.is_api?
|
2013-07-29 01:13:13 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def current_user
|
2013-10-09 00:10:37 -04:00
|
|
|
current_user_provider.current_user
|
|
|
|
end
|
2013-03-25 21:04:28 -04:00
|
|
|
|
2013-10-09 00:10:37 -04:00
|
|
|
private
|
2013-03-25 21:04:28 -04:00
|
|
|
|
2013-10-09 00:10:37 -04:00
|
|
|
def current_user_provider
|
|
|
|
@current_user_provider ||= Discourse.current_user_provider.new(request.env)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|