authn 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/authn/config.rb +1 -3
- data/lib/authn/model.rb +1 -5
- data/lib/authn/session.rb +46 -52
- data/lib/authn/version.rb +1 -1
- metadata +4 -4
data/lib/authn/config.rb
CHANGED
data/lib/authn/model.rb
CHANGED
@@ -31,11 +31,7 @@ module AuthN
|
|
31
31
|
# Check to see if the instance exists and if a password was given
|
32
32
|
if instance && password
|
33
33
|
# Check to see if the instance can authenticate with password
|
34
|
-
|
35
|
-
instance
|
36
|
-
else
|
37
|
-
false
|
38
|
-
end
|
34
|
+
instance.authenticate(password) ? instance : false
|
39
35
|
end
|
40
36
|
|
41
37
|
# Return instance if account was found and password matched
|
data/lib/authn/session.rb
CHANGED
@@ -1,72 +1,66 @@
|
|
1
1
|
module AuthN
|
2
2
|
module Session
|
3
|
-
def
|
4
|
-
|
3
|
+
def login(identifiers, klass = AuthN.config.account_klass)
|
4
|
+
generate_session_and_instance_from find_instance_klass(klass).authenticate identifiers
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def auto_login(instance)
|
13
|
-
instance_and_session instance
|
14
|
-
end
|
7
|
+
def auto_login(instance)
|
8
|
+
instance_and_session instance
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def logged_in?(instance = nil, klass = AuthN.config.account_klass)
|
12
|
+
klass = instance.class if instance
|
13
|
+
klass = find_instance_klass klass unless instance
|
14
|
+
check_session klass
|
15
|
+
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
def logout(instance = nil, klass = AuthN.config.account_klass)
|
18
|
+
klass = instance.class if instance
|
19
|
+
klass = find_instance_klass klass unless instance
|
20
|
+
destroy_session klass
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
def current_user(klass = AuthN.config.account_klass)
|
24
|
+
@current_user ||= get_session klass_as_name klass
|
25
|
+
end
|
31
26
|
|
32
|
-
|
27
|
+
alias_method :current_account, :current_user
|
33
28
|
|
34
|
-
|
29
|
+
private
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
def find_instance_klass(klass)
|
32
|
+
const_get klass.capitalize
|
33
|
+
end
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
def klass_as_name(klass)
|
36
|
+
klass.name.downcase
|
37
|
+
end
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
def generate_session_and_instance_from(instance)
|
40
|
+
instance.tap { instance_and_session instance if instance }
|
41
|
+
end
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
def instance_and_session(instance)
|
44
|
+
instance.tap { |instance| create_session instance.class, instance }
|
45
|
+
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
def create_session(klass, instance)
|
48
|
+
key = AuthN.config.session_key_function.call klass_as_name klass
|
49
|
+
session[key] = instance.send AuthN.config.model_id_method
|
50
|
+
end
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
52
|
+
def destroy_session(klass)
|
53
|
+
key = AuthN.config.session_key_function.call klass_as_name klass
|
54
|
+
session.delete key
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
def check_session(klass)
|
58
|
+
get_session(klass).present?
|
59
|
+
end
|
65
60
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
61
|
+
def get_session(klass)
|
62
|
+
key = AuthN.config.session_key_function.call klass_as_name klass
|
63
|
+
session[key]
|
70
64
|
end
|
71
65
|
end
|
72
66
|
end
|
data/lib/authn/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: 4517271983309580040
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash:
|
144
|
+
hash: 4517271983309580040
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
147
|
rubygems_version: 1.8.24
|