monban 0.3.1 → 1.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -13
- data/NEWS.rdoc +4 -0
- data/lib/monban.rb +5 -2
- data/lib/monban/configuration.rb +20 -2
- data/lib/monban/param_transformer.rb +38 -0
- data/lib/monban/services/sign_up.rb +1 -1
- data/lib/monban/version.rb +2 -2
- data/spec/monban_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c994797ca1338ca8d78bb15bdfeaa5585bdf555a
|
4
|
+
data.tar.gz: 0ae31c41b9a1b9b08e8888a354d440051ed30eef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d4db22086b7359a92202a55cb033f5255434146e214d655974db3ae8d4b039232188bbfc41f715eb6ce040c80c02b55295b51dc2799c6ffe77f76a4ad51ffa7
|
7
|
+
data.tar.gz: ccd82bf884f619b75f15b0fd4a3d91248f600d0d3aa660964c6a565a20623cf8e868eac62ac91a8bde5caae667d54693f0e11f1e2494fc3c6c49311bc8f92302
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
monban (0.
|
4
|
+
monban (1.0.0)
|
5
5
|
bcrypt
|
6
6
|
rails
|
7
7
|
warden
|
@@ -46,8 +46,8 @@ GEM
|
|
46
46
|
minitest (~> 5.1)
|
47
47
|
thread_safe (~> 0.3, >= 0.3.4)
|
48
48
|
tzinfo (~> 1.1)
|
49
|
-
arel (6.0.
|
50
|
-
bcrypt (3.1.
|
49
|
+
arel (6.0.3)
|
50
|
+
bcrypt (3.1.11)
|
51
51
|
builder (3.2.2)
|
52
52
|
capybara (2.4.4)
|
53
53
|
mime-types (>= 1.16)
|
@@ -55,16 +55,17 @@ GEM
|
|
55
55
|
rack (>= 1.0.0)
|
56
56
|
rack-test (>= 0.5.4)
|
57
57
|
xpath (~> 2.0)
|
58
|
+
concurrent-ruby (1.0.2)
|
58
59
|
diff-lcs (1.2.5)
|
59
60
|
erubis (2.7.0)
|
60
|
-
globalid (0.3.
|
61
|
+
globalid (0.3.6)
|
61
62
|
activesupport (>= 4.1.0)
|
62
63
|
i18n (0.7.0)
|
63
64
|
json (1.8.3)
|
64
65
|
loofah (2.0.2)
|
65
66
|
nokogiri (>= 1.5.9)
|
66
|
-
mail (2.6.
|
67
|
-
mime-types (>= 1.16, <
|
67
|
+
mail (2.6.4)
|
68
|
+
mime-types (>= 1.16, < 4)
|
68
69
|
mime-types (2.6.1)
|
69
70
|
mini_portile (0.6.2)
|
70
71
|
minitest (5.7.0)
|
@@ -119,18 +120,19 @@ GEM
|
|
119
120
|
rspec-mocks (~> 3.3.0)
|
120
121
|
rspec-support (~> 3.3.0)
|
121
122
|
rspec-support (3.3.0)
|
122
|
-
sprockets (3.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
123
|
+
sprockets (3.6.0)
|
124
|
+
concurrent-ruby (~> 1.0)
|
125
|
+
rack (> 1, < 3)
|
126
|
+
sprockets-rails (3.0.4)
|
127
|
+
actionpack (>= 4.0)
|
128
|
+
activesupport (>= 4.0)
|
129
|
+
sprockets (>= 3.0.0)
|
128
130
|
sqlite3 (1.3.10)
|
129
131
|
thor (0.19.1)
|
130
132
|
thread_safe (0.3.5)
|
131
133
|
tzinfo (1.2.2)
|
132
134
|
thread_safe (~> 0.1)
|
133
|
-
warden (1.2.
|
135
|
+
warden (1.2.6)
|
134
136
|
rack (>= 1.0)
|
135
137
|
xpath (2.0.0)
|
136
138
|
nokogiri (~> 1.3)
|
@@ -146,3 +148,6 @@ DEPENDENCIES
|
|
146
148
|
rspec
|
147
149
|
rspec-rails
|
148
150
|
sqlite3
|
151
|
+
|
152
|
+
BUNDLED WITH
|
153
|
+
1.11.2
|
data/NEWS.rdoc
CHANGED
data/lib/monban.rb
CHANGED
@@ -8,6 +8,7 @@ require "monban/failure_app"
|
|
8
8
|
require "monban/back_door"
|
9
9
|
require "monban/warden_setup"
|
10
10
|
require "monban/field_map"
|
11
|
+
require "monban/param_transformer"
|
11
12
|
require "monban/strategies/password_strategy"
|
12
13
|
require "active_support/core_ext/module/attribute_accessors"
|
13
14
|
|
@@ -73,8 +74,10 @@ module Monban
|
|
73
74
|
# @return [User] if user is found
|
74
75
|
# @return [nil] if no user is found
|
75
76
|
def self.lookup(params, field_map)
|
76
|
-
|
77
|
-
|
77
|
+
if params.present?
|
78
|
+
fields = FieldMap.new(params, field_map).to_fields
|
79
|
+
self.config.find_method.call(fields)
|
80
|
+
end
|
78
81
|
end
|
79
82
|
|
80
83
|
# Puts monban into test mode. This will disable hashing passwords
|
data/lib/monban/configuration.rb
CHANGED
@@ -12,6 +12,7 @@ module Monban
|
|
12
12
|
attr_accessor :no_login_handler, :no_login_redirect
|
13
13
|
attr_accessor :authentication_strategy
|
14
14
|
attr_accessor :warden_serialize_into_session, :warden_serialize_from_session
|
15
|
+
attr_accessor :param_transformations
|
15
16
|
|
16
17
|
attr_writer :user_class
|
17
18
|
|
@@ -21,13 +22,17 @@ module Monban
|
|
21
22
|
setup_notices
|
22
23
|
setup_services
|
23
24
|
setup_warden
|
25
|
+
setup_param_transformations
|
24
26
|
end
|
25
27
|
|
26
28
|
# Default creation method. Can be overriden via {Monban.configure}
|
27
29
|
#
|
28
30
|
# @see #creation_method=
|
29
31
|
def default_creation_method
|
30
|
-
->(params)
|
32
|
+
->(params) do
|
33
|
+
updated_params = transform_params(params)
|
34
|
+
Monban.config.user_class.create(updated_params)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
# Default hashing method. Can be overriden via {Monban.configure}
|
@@ -48,7 +53,10 @@ module Monban
|
|
48
53
|
# @see #find_method=
|
49
54
|
# @see Monban.config.user_class
|
50
55
|
def default_find_method
|
51
|
-
->(params)
|
56
|
+
->(params) do
|
57
|
+
updated_params = transform_params(params)
|
58
|
+
Monban.config.user_class.find_by(updated_params)
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
62
|
# Default token comparison method. Can be overriden via {Monban.configure}
|
@@ -123,5 +131,15 @@ module Monban
|
|
123
131
|
@warden_serialize_into_session = -> (user) { user.id }
|
124
132
|
@warden_serialize_from_session = -> (id) { Monban.config.user_class.find_by(id: id) }
|
125
133
|
end
|
134
|
+
|
135
|
+
def setup_param_transformations
|
136
|
+
@param_transformations = {
|
137
|
+
email: ->(value) { value.downcase }
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
def transform_params(params)
|
142
|
+
ParamTransformer.new(params, param_transformations).to_h
|
143
|
+
end
|
126
144
|
end
|
127
145
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Monban
|
2
|
+
# Parameter transformer. Sanitizes and transforms parameter values
|
3
|
+
# @since 1.0.0
|
4
|
+
class ParamTransformer
|
5
|
+
# Initialize parameter transformer
|
6
|
+
#
|
7
|
+
# @param params [ActionController::Parameters] parameters to be altered
|
8
|
+
def initialize(params, transformations)
|
9
|
+
@params = params
|
10
|
+
@transformations = transformations
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the transformed parameters
|
14
|
+
def to_h
|
15
|
+
sanitized_params.each_with_object({}) do |(key, value), hash|
|
16
|
+
hash[key] = transform(key, value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :params, :transformations
|
23
|
+
|
24
|
+
def sanitized_params
|
25
|
+
params.to_h
|
26
|
+
end
|
27
|
+
|
28
|
+
def transform(key, value)
|
29
|
+
return value unless value.is_a? String
|
30
|
+
|
31
|
+
if transformations.key?(key)
|
32
|
+
transformations[key].call(value)
|
33
|
+
else
|
34
|
+
value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/monban/version.rb
CHANGED
data/spec/monban_spec.rb
CHANGED
@@ -12,9 +12,9 @@ describe 'Monban' do
|
|
12
12
|
expect(Monban.compare_token('password', 'password')).to be_truthy
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "does not lookup with empty params" do
|
16
16
|
allow(Monban::FieldMap).to receive(:new).and_return(fake_field_map)
|
17
|
-
with_monban_config(find_method: -> (conditions) {
|
17
|
+
with_monban_config(find_method: -> (conditions) { raise }) do
|
18
18
|
expect(-> { Monban.lookup({}, {}) }).not_to raise_exception
|
19
19
|
end
|
20
20
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halogenandtoast
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/monban/controller_helpers.rb
|
162
162
|
- lib/monban/failure_app.rb
|
163
163
|
- lib/monban/field_map.rb
|
164
|
+
- lib/monban/param_transformer.rb
|
164
165
|
- lib/monban/railtie.rb
|
165
166
|
- lib/monban/services.rb
|
166
167
|
- lib/monban/services/authentication.rb
|
@@ -254,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
255
|
version: '0'
|
255
256
|
requirements: []
|
256
257
|
rubyforge_project:
|
257
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.5.1
|
258
259
|
signing_key:
|
259
260
|
specification_version: 4
|
260
261
|
summary: Making rails authentication as simple as possible
|