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