2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
module CurrentUser
|
2013-04-11 14:24:08 +08:00
|
|
|
def self.has_auth_cookie?(env)
|
2013-10-09 12:10:37 +08:00
|
|
|
Discourse.current_user_provider.new(env).has_auth_cookie?
|
2013-04-11 14:24:08 +08:00
|
|
|
end
|
|
|
|
|
2013-02-15 16:23:40 +08:00
|
|
|
def self.lookup_from_env(env)
|
2013-10-09 12:10:37 +08:00
|
|
|
Discourse.current_user_provider.new(env).current_user
|
2013-02-24 18:42:04 +08:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:13:13 +08:00
|
|
|
# can be used to pretend current user does no exist, for CSRF attacks
|
|
|
|
def clear_current_user
|
2013-10-09 12:10:37 +08:00
|
|
|
@current_user_provider = Discourse.current_user_provider.new({})
|
2013-07-29 13:13:13 +08:00
|
|
|
end
|
|
|
|
|
2018-11-12 22:34:12 +08:00
|
|
|
def log_on_user(user, opts = {})
|
|
|
|
current_user_provider.log_on_user(user, session, cookies, opts)
|
2017-06-01 16:19:42 +08:00
|
|
|
user.logged_in
|
2013-02-24 18:50:34 +08:00
|
|
|
end
|
|
|
|
|
2013-10-09 12:10:37 +08:00
|
|
|
def log_off_user
|
|
|
|
current_user_provider.log_off_user(session, cookies)
|
2013-02-15 16:23:40 +08:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:13:13 +08:00
|
|
|
def is_api?
|
2013-10-09 12:10:37 +08:00
|
|
|
current_user_provider.is_api?
|
2013-07-29 13:13:13 +08:00
|
|
|
end
|
|
|
|
|
2016-12-16 09:05:20 +08:00
|
|
|
def is_user_api?
|
|
|
|
current_user_provider.is_user_api?
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def current_user
|
2015-01-28 09:56:25 +08:00
|
|
|
current_user_provider.current_user
|
2013-10-09 12:10:37 +08:00
|
|
|
end
|
2013-03-26 09:04:28 +08:00
|
|
|
|
2016-07-25 10:07:31 +08:00
|
|
|
def refresh_session(user)
|
|
|
|
current_user_provider.refresh_session(user, session, cookies)
|
|
|
|
end
|
|
|
|
|
2013-10-09 12:10:37 +08:00
|
|
|
private
|
2013-03-26 09:04:28 +08:00
|
|
|
|
2013-10-09 12:10:37 +08:00
|
|
|
def current_user_provider
|
|
|
|
@current_user_provider ||= Discourse.current_user_provider.new(request.env)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|