-
Notifications
You must be signed in to change notification settings - Fork 17
/
controller_helpers.rb
39 lines (34 loc) · 1.32 KB
/
controller_helpers.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 Warden
module GitHub
module Rails
module ControllerHelpers
def self.included(klass)
klass.helper_method(:github_authenticated?, :github_user)
end
# Initiates the OAuth flow if not already authenticated for the
# specified scope.
def github_authenticate!(scope=Rails.default_scope)
request.env['warden'].authenticate!(scope: scope)
end
# Logs out a user if currently logged in for the specified scope.
def github_logout(scope=Rails.default_scope)
request.env['warden'].logout(scope)
end
# Checks whether a user is logged in for the specified scope.
def github_authenticated?(scope=Rails.default_scope)
request.env['warden'].authenticated?(scope)
end
# Returns the currently signed in user for the specified scope. See the
# documentation for Warden::GitHub::User for available methods.
def github_user(scope=Rails.default_scope)
request.env['warden'].user(scope)
end
# Accessor for the currently signed in user's session. This will be
# cleared once logged out.
def github_session(scope=Rails.default_scope)
request.env['warden'].session(scope) if github_authenticated?(scope)
end
end
end
end
end