2013-02-05 13:16:51 -06:00
|
|
|
module CurrentUser
|
|
|
|
|
2013-04-11 01:24:08 -05:00
|
|
|
def self.has_auth_cookie?(env)
|
2013-10-08 23:10:37 -05:00
|
|
|
Discourse.current_user_provider.new(env).has_auth_cookie?
|
2013-04-11 01:24:08 -05:00
|
|
|
end
|
|
|
|
|
2013-02-15 02:23:40 -06:00
|
|
|
def self.lookup_from_env(env)
|
2013-10-08 23:10:37 -05:00
|
|
|
Discourse.current_user_provider.new(env).current_user
|
2013-02-24 04:42:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-07-29 00:13:13 -05:00
|
|
|
# can be used to pretend current user does no exist, for CSRF attacks
|
|
|
|
def clear_current_user
|
2013-10-08 23:10:37 -05:00
|
|
|
@current_user_provider = Discourse.current_user_provider.new({})
|
2013-07-29 00:13:13 -05:00
|
|
|
end
|
|
|
|
|
2013-02-24 04:42:04 -06:00
|
|
|
def log_on_user(user)
|
2013-10-08 23:10:37 -05:00
|
|
|
current_user_provider.log_on_user(user,session,cookies)
|
2013-02-24 04:50:34 -06:00
|
|
|
end
|
|
|
|
|
2013-10-08 23:10:37 -05:00
|
|
|
def log_off_user
|
|
|
|
current_user_provider.log_off_user(session,cookies)
|
2013-02-15 02:23:40 -06:00
|
|
|
end
|
|
|
|
|
2013-07-29 00:13:13 -05:00
|
|
|
def is_api?
|
2013-10-08 23:10:37 -05:00
|
|
|
current_user_provider.is_api?
|
2013-07-29 00:13:13 -05:00
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
def current_user
|
2015-01-27 19:56:25 -06:00
|
|
|
current_user_provider.current_user
|
2013-10-08 23:10:37 -05:00
|
|
|
end
|
2013-03-25 20:04:28 -05:00
|
|
|
|
2016-07-24 21:07:31 -05:00
|
|
|
def refresh_session(user)
|
|
|
|
current_user_provider.refresh_session(user,session,cookies)
|
|
|
|
end
|
|
|
|
|
2013-10-08 23:10:37 -05:00
|
|
|
private
|
2013-03-25 20:04:28 -05:00
|
|
|
|
2013-10-08 23:10:37 -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
|