simplest_auth 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -9
- data/lib/simplest_auth/model.rb +15 -16
- data/lib/simplest_auth/version.rb +1 -1
- metadata +3 -7
data/Rakefile
CHANGED
@@ -7,15 +7,14 @@ require 'lib/simplest_auth/version'
|
|
7
7
|
task :default => :test
|
8
8
|
|
9
9
|
spec = Gem::Specification.new do |s|
|
10
|
-
s.name
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.test_files = Dir.glob("test/**/*_test.rb")
|
10
|
+
s.name = 'simplest_auth'
|
11
|
+
s.version = SimplestAuth::Version.to_s
|
12
|
+
s.summary = "Simple implementation of authentication for Rails"
|
13
|
+
s.author = 'Tony Pitale'
|
14
|
+
s.email = 'tony.pitale@viget.com'
|
15
|
+
s.homepage = 'http://viget.com/extend'
|
16
|
+
s.files = %w(README.textile Rakefile) + Dir.glob("lib/**/*")
|
17
|
+
s.test_files = Dir.glob("test/**/*_test.rb")
|
19
18
|
|
20
19
|
s.add_dependency('bcrypt-ruby', '~> 2.1.1')
|
21
20
|
end
|
data/lib/simplest_auth/model.rb
CHANGED
@@ -8,7 +8,7 @@ module SimplestAuth
|
|
8
8
|
attr_accessor :password, :password_confirmation
|
9
9
|
end
|
10
10
|
|
11
|
-
if base.active_record?
|
11
|
+
if base.active_record? || base.mongo_mapper?
|
12
12
|
base.class_eval do
|
13
13
|
before_save :hash_password, :if => :password_required?
|
14
14
|
end
|
@@ -28,30 +28,33 @@ module SimplestAuth
|
|
28
28
|
defined?(DataMapper)
|
29
29
|
end
|
30
30
|
|
31
|
+
def mongo_mapper?
|
32
|
+
defined?(MongoMapper)
|
33
|
+
end
|
34
|
+
|
31
35
|
def authenticate(email, password)
|
32
|
-
user = nil
|
33
36
|
if active_record?
|
34
|
-
|
35
|
-
elsif data_mapper?
|
36
|
-
|
37
|
+
klass = find_by_email(email)
|
38
|
+
elsif data_mapper? || mongo_mapper?
|
39
|
+
klass = first(:email => email)
|
37
40
|
end
|
38
41
|
|
39
|
-
(
|
42
|
+
(klass && klass.authentic?(password)) ? klass : nil
|
40
43
|
end
|
41
44
|
|
42
45
|
def authenticate_by(ident)
|
43
46
|
if active_record?
|
44
47
|
instance_eval <<-EOM
|
45
48
|
def authenticate(#{ident}, password)
|
46
|
-
|
47
|
-
(
|
49
|
+
klass = find_by_#{ident}(#{ident})
|
50
|
+
(klass && klass.authentic?(password)) ? klass : nil
|
48
51
|
end
|
49
52
|
EOM
|
50
|
-
elsif data_mapper?
|
53
|
+
elsif data_mapper? || mongo_mapper?
|
51
54
|
instance_eval <<-EOM
|
52
55
|
def authenticate(#{ident}, password)
|
53
|
-
|
54
|
-
(
|
56
|
+
klass = first(:#{ident} => #{ident})
|
57
|
+
(klass && klass.authentic?(password)) ? klass : nil
|
55
58
|
end
|
56
59
|
EOM
|
57
60
|
end
|
@@ -72,11 +75,7 @@ module SimplestAuth
|
|
72
75
|
RecordNotFound = Class.new(StandardError) unless defined?(RecordNotFound)
|
73
76
|
|
74
77
|
def authentic?(password)
|
75
|
-
|
76
|
-
return Password.new(self.crypted_password) == password
|
77
|
-
rescue BCrypt::Errors::InvalidHash
|
78
|
-
return false
|
79
|
-
end
|
78
|
+
Password.new(self.crypted_password) == password
|
80
79
|
end
|
81
80
|
|
82
81
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplest_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,10 +37,6 @@ files:
|
|
37
37
|
- lib/simplest_auth/model.rb
|
38
38
|
- lib/simplest_auth/version.rb
|
39
39
|
- lib/simplest_auth.rb
|
40
|
-
- test/unit/simplest_auth/ar_model_test.rb
|
41
|
-
- test/unit/simplest_auth/controller_test.rb
|
42
|
-
- test/unit/simplest_auth/dm_model_test.rb
|
43
|
-
- test/unit/simplest_auth/model_test.rb
|
44
40
|
has_rdoc: true
|
45
41
|
homepage: http://viget.com/extend
|
46
42
|
licenses: []
|
@@ -64,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
60
|
version:
|
65
61
|
requirements: []
|
66
62
|
|
67
|
-
rubyforge_project:
|
63
|
+
rubyforge_project:
|
68
64
|
rubygems_version: 1.3.5
|
69
65
|
signing_key:
|
70
66
|
specification_version: 3
|