letmein 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -4
- data/VERSION +1 -1
- data/letmein.gemspec +1 -2
- data/lib/letmein.rb +3 -1
- data/test/letmein_test.rb +15 -2
- metadata +10 -11
- data/Gemfile.lock +0 -97
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
letmein
|
2
|
-
=======
|
1
|
+
# letmein [![Build Status](http://travis-ci.org/GBH/letmein.png)](http://travis-ci.org/GBH/letmein)
|
3
2
|
|
4
3
|
**letmein** is a minimalistic authentication plugin for Rails 3 applications. It doesn't have anything other than the UserSession (or WhateverSession) object that you can use to authenticate logins.
|
5
4
|
|
@@ -85,13 +84,15 @@ Overriding Session Authentication
|
|
85
84
|
By default user will be logged in if provided email and password match. If you need to add a bit more logic to that you'll need to create your own session object. In the following example we do an additional check to see if user is 'approved' before letting him in.
|
86
85
|
|
87
86
|
class MySession < LetMeIn::Session
|
88
|
-
|
87
|
+
# Model that is being authenticated is derived from the class name
|
88
|
+
# If you're authenticating multiple models you need to specify which one
|
89
|
+
@model = 'User'
|
89
90
|
|
90
91
|
def authenticate
|
91
92
|
super # need to authenticate with email/password first
|
92
93
|
if user && user.is_approved?
|
93
94
|
# adding a validation error will prevent login
|
94
|
-
errors.add :base,
|
95
|
+
errors.add :base, "You are not approved yet, #{user.name}."
|
95
96
|
end
|
96
97
|
end
|
97
98
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/letmein.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{letmein}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oleg Khabarov"]
|
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".travis.yml",
|
21
21
|
"Gemfile",
|
22
|
-
"Gemfile.lock",
|
23
22
|
"LICENSE",
|
24
23
|
"README.md",
|
25
24
|
"Rakefile",
|
data/lib/letmein.rb
CHANGED
@@ -53,7 +53,9 @@ module LetMeIn
|
|
53
53
|
validate :authenticate
|
54
54
|
|
55
55
|
def initialize(params = { })
|
56
|
-
|
56
|
+
model = self.class.to_s.gsub('Session', '')
|
57
|
+
model = LetMeIn.config.models.member?(model) ? model : LetMeIn.config.models.first
|
58
|
+
self.class.model ||= model
|
57
59
|
self.class.attribute ||= LetMeIn.accessor(:attribute, LetMeIn.config.models.index(self.class.model))
|
58
60
|
self.login = params[:login] || params[self.class.attribute.to_sym]
|
59
61
|
self.password = params[:password]
|
data/test/letmein_test.rb
CHANGED
@@ -11,20 +11,25 @@ class User < ActiveRecord::Base ; end
|
|
11
11
|
class Admin < ActiveRecord::Base ; end
|
12
12
|
|
13
13
|
class OpenSession < LetMeIn::Session
|
14
|
-
@model, @attribute = 'User', 'email'
|
14
|
+
# @model, @attribute = 'User', 'email'
|
15
15
|
def authenticate
|
16
16
|
super
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
class ClosedSession < LetMeIn::Session
|
21
|
-
@model, @attribute = 'User', 'email'
|
21
|
+
# @model, @attribute = 'User', 'email'
|
22
22
|
def authenticate
|
23
23
|
super
|
24
24
|
errors.add :base, "You shall not pass #{user.email}"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
class CustomAdminSession < LetMeIn::Session
|
29
|
+
@model = 'Admin'
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
|
28
33
|
class LetMeInTest < Test::Unit::TestCase
|
29
34
|
|
30
35
|
def setup
|
@@ -209,4 +214,12 @@ class LetMeInTest < Test::Unit::TestCase
|
|
209
214
|
assert session.invalid?
|
210
215
|
assert_equal 'You shall not pass test@test.test', session.errors[:base].first
|
211
216
|
end
|
217
|
+
|
218
|
+
def test_custom_admin_session
|
219
|
+
init_custom_configuration
|
220
|
+
admin = Admin.create!(:username => 'admin', :password => 'pass')
|
221
|
+
session = CustomAdminSession.new(:username => 'admin', :password => 'pass')
|
222
|
+
assert session.valid?
|
223
|
+
assert_equal admin, session.admin
|
224
|
+
end
|
212
225
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: letmein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &70092744394500 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70092744394500
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bcrypt-ruby
|
28
|
-
requirement: &
|
28
|
+
requirement: &70092744393800 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70092744393800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70092744392980 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70092744392980
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &70092744391800 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: 1.5.2
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70092744391800
|
59
59
|
description: minimalistic authentication
|
60
60
|
email: oleg@khabarov.ca
|
61
61
|
executables: []
|
@@ -66,7 +66,6 @@ extra_rdoc_files:
|
|
66
66
|
files:
|
67
67
|
- .travis.yml
|
68
68
|
- Gemfile
|
69
|
-
- Gemfile.lock
|
70
69
|
- LICENSE
|
71
70
|
- README.md
|
72
71
|
- Rakefile
|
@@ -90,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
89
|
version: '0'
|
91
90
|
segments:
|
92
91
|
- 0
|
93
|
-
hash:
|
92
|
+
hash: 3220175875502170728
|
94
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
94
|
none: false
|
96
95
|
requirements:
|
data/Gemfile.lock
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
actionmailer (3.1.0)
|
5
|
-
actionpack (= 3.1.0)
|
6
|
-
mail (~> 2.3.0)
|
7
|
-
actionpack (3.1.0)
|
8
|
-
activemodel (= 3.1.0)
|
9
|
-
activesupport (= 3.1.0)
|
10
|
-
builder (~> 3.0.0)
|
11
|
-
erubis (~> 2.7.0)
|
12
|
-
i18n (~> 0.6)
|
13
|
-
rack (~> 1.3.2)
|
14
|
-
rack-cache (~> 1.0.3)
|
15
|
-
rack-mount (~> 0.8.2)
|
16
|
-
rack-test (~> 0.6.1)
|
17
|
-
sprockets (~> 2.0.0)
|
18
|
-
activemodel (3.1.0)
|
19
|
-
activesupport (= 3.1.0)
|
20
|
-
bcrypt-ruby (~> 3.0.0)
|
21
|
-
builder (~> 3.0.0)
|
22
|
-
i18n (~> 0.6)
|
23
|
-
activerecord (3.1.0)
|
24
|
-
activemodel (= 3.1.0)
|
25
|
-
activesupport (= 3.1.0)
|
26
|
-
arel (~> 2.2.1)
|
27
|
-
tzinfo (~> 0.3.29)
|
28
|
-
activeresource (3.1.0)
|
29
|
-
activemodel (= 3.1.0)
|
30
|
-
activesupport (= 3.1.0)
|
31
|
-
activesupport (3.1.0)
|
32
|
-
multi_json (~> 1.0)
|
33
|
-
arel (2.2.1)
|
34
|
-
bcrypt-ruby (3.0.0)
|
35
|
-
builder (3.0.0)
|
36
|
-
erubis (2.7.0)
|
37
|
-
git (1.2.5)
|
38
|
-
hike (1.2.1)
|
39
|
-
i18n (0.6.0)
|
40
|
-
jeweler (1.5.2)
|
41
|
-
bundler (~> 1.0.0)
|
42
|
-
git (>= 1.2.5)
|
43
|
-
rake
|
44
|
-
mail (2.3.0)
|
45
|
-
i18n (>= 0.4.0)
|
46
|
-
mime-types (~> 1.16)
|
47
|
-
treetop (~> 1.4.8)
|
48
|
-
mime-types (1.16)
|
49
|
-
multi_json (1.0.3)
|
50
|
-
polyglot (0.3.2)
|
51
|
-
rack (1.3.2)
|
52
|
-
rack-cache (1.0.3)
|
53
|
-
rack (>= 0.4)
|
54
|
-
rack-mount (0.8.3)
|
55
|
-
rack (>= 1.0.0)
|
56
|
-
rack-ssl (1.3.2)
|
57
|
-
rack
|
58
|
-
rack-test (0.6.1)
|
59
|
-
rack (>= 1.0)
|
60
|
-
rails (3.1.0)
|
61
|
-
actionmailer (= 3.1.0)
|
62
|
-
actionpack (= 3.1.0)
|
63
|
-
activerecord (= 3.1.0)
|
64
|
-
activeresource (= 3.1.0)
|
65
|
-
activesupport (= 3.1.0)
|
66
|
-
bundler (~> 1.0)
|
67
|
-
railties (= 3.1.0)
|
68
|
-
railties (3.1.0)
|
69
|
-
actionpack (= 3.1.0)
|
70
|
-
activesupport (= 3.1.0)
|
71
|
-
rack-ssl (~> 1.3.2)
|
72
|
-
rake (>= 0.8.7)
|
73
|
-
rdoc (~> 3.4)
|
74
|
-
thor (~> 0.14.6)
|
75
|
-
rake (0.9.2)
|
76
|
-
rdoc (3.9.4)
|
77
|
-
sprockets (2.0.0)
|
78
|
-
hike (~> 1.2)
|
79
|
-
rack (~> 1.0)
|
80
|
-
tilt (!= 1.3.0, ~> 1.1)
|
81
|
-
sqlite3 (1.3.4)
|
82
|
-
thor (0.14.6)
|
83
|
-
tilt (1.3.3)
|
84
|
-
treetop (1.4.10)
|
85
|
-
polyglot
|
86
|
-
polyglot (>= 0.3.1)
|
87
|
-
tzinfo (0.3.29)
|
88
|
-
|
89
|
-
PLATFORMS
|
90
|
-
ruby
|
91
|
-
|
92
|
-
DEPENDENCIES
|
93
|
-
bcrypt-ruby
|
94
|
-
bundler (~> 1.0.0)
|
95
|
-
jeweler (~> 1.5.2)
|
96
|
-
rails (>= 3.0.0)
|
97
|
-
sqlite3
|