blob: d1c0711072e882c6da7b8d07ee364d13cf3bb885 (
plain)
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
|
class UserSession
include ActiveModel::Conversion
include StaticModel
extend ActiveModel::Naming
def authenticate(auth_opts)
authenticate_via(auth_opts) do |network, options|
network.authenticate(options)
end
end
def authenticate_by_token(auth_opts)
result = authenticate_via(auth_opts) do |network, options|
network.authenticate_by_token(options)
end
result
end
private
def authenticate_via(options, &block)
user = block.call(Network.new, options)
if user
return User.new(user)
else
nil
end
rescue
nil
end
end
|