forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent_user.rb
39 lines (28 loc) · 816 Bytes
/
current_user.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module CurrentUser
def self.has_auth_cookie?(env)
Discourse.current_user_provider.new(env).has_auth_cookie?
end
def self.lookup_from_env(env)
Discourse.current_user_provider.new(env).current_user
end
# can be used to pretend current user does no exist, for CSRF attacks
def clear_current_user
@current_user_provider = Discourse.current_user_provider.new({})
end
def log_on_user(user)
current_user_provider.log_on_user(user,session,cookies)
end
def log_off_user
current_user_provider.log_off_user(session,cookies)
end
def is_api?
current_user_provider.is_api?
end
def current_user
current_user_provider.current_user
end
private
def current_user_provider
@current_user_provider ||= Discourse.current_user_provider.new(request.env)
end
end