simplest_auth 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -8
- data/lib/simplest_auth/model.rb +13 -8
- data/lib/simplest_auth/version.rb +1 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -7,14 +7,15 @@ 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.
|
10
|
+
s.name = 'simplest_auth'
|
11
|
+
s.rubyforge_project = 'viget'
|
12
|
+
s.version = SimplestAuth::Version.to_s
|
13
|
+
s.summary = "Simple implementation of authentication for Rails"
|
14
|
+
s.author = 'Tony Pitale'
|
15
|
+
s.email = 'tony.pitale@viget.com'
|
16
|
+
s.homepage = 'http://viget.com/extend'
|
17
|
+
s.files = %w(README.textile Rakefile) + Dir.glob("lib/**/*")
|
18
|
+
s.test_files = Dir.glob("test/**/*_test.rb")
|
18
19
|
|
19
20
|
s.add_dependency('bcrypt-ruby', '~> 2.1.1')
|
20
21
|
end
|
data/lib/simplest_auth/model.rb
CHANGED
@@ -29,28 +29,29 @@ module SimplestAuth
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def authenticate(email, password)
|
32
|
+
user = nil
|
32
33
|
if active_record?
|
33
|
-
|
34
|
+
user = find_by_email(email)
|
34
35
|
elsif data_mapper?
|
35
|
-
|
36
|
+
user = first(:email => email)
|
36
37
|
end
|
37
38
|
|
38
|
-
(
|
39
|
+
(user && user.authentic?(password)) ? user : nil
|
39
40
|
end
|
40
41
|
|
41
42
|
def authenticate_by(ident)
|
42
43
|
if active_record?
|
43
44
|
instance_eval <<-EOM
|
44
45
|
def authenticate(#{ident}, password)
|
45
|
-
|
46
|
-
(
|
46
|
+
user = find_by_#{ident}(#{ident})
|
47
|
+
(user && user.authentic?(password)) ? user : nil
|
47
48
|
end
|
48
49
|
EOM
|
49
50
|
elsif data_mapper?
|
50
51
|
instance_eval <<-EOM
|
51
52
|
def authenticate(#{ident}, password)
|
52
|
-
|
53
|
-
(
|
53
|
+
user = first(:#{ident} => #{ident})
|
54
|
+
(user && user.authentic?(password)) ? user : nil
|
54
55
|
end
|
55
56
|
EOM
|
56
57
|
end
|
@@ -71,7 +72,11 @@ module SimplestAuth
|
|
71
72
|
RecordNotFound = Class.new(StandardError) unless defined?(RecordNotFound)
|
72
73
|
|
73
74
|
def authentic?(password)
|
74
|
-
|
75
|
+
begin
|
76
|
+
return Password.new(self.crypted_password) == password
|
77
|
+
rescue BCrypt::Errors::InvalidHash
|
78
|
+
return false
|
79
|
+
end
|
75
80
|
end
|
76
81
|
|
77
82
|
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.3
|
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-10-13 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version:
|
65
65
|
requirements: []
|
66
66
|
|
67
|
-
rubyforge_project:
|
67
|
+
rubyforge_project: viget
|
68
68
|
rubygems_version: 1.3.5
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|