2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
|
2018-11-12 08:34:12 -06:00
|
|
|
def log_on_user(user, opts = {})
|
|
|
|
current_user_provider.log_on_user(user, session, cookies, opts)
|
2017-06-01 03:19:42 -05:00
|
|
|
user.logged_in
|
2013-02-24 04:50:34 -06:00
|
|
|
end
|
|
|
|
|
2013-10-08 23:10:37 -05:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2016-12-15 19:05:20 -06:00
|
|
|
def is_user_api?
|
|
|
|
current_user_provider.is_user_api?
|
|
|
|
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)
|
2017-07-27 20:20:09 -05:00
|
|
|
current_user_provider.refresh_session(user, session, cookies)
|
2016-07-24 21:07:31 -05:00
|
|
|
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
|