puffer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +98 -80
- data/README.md +6 -0
- data/Rakefile +1 -1
- data/app/assets/javascripts/puffer/puffer.js +15 -3
- data/app/assets/javascripts/puffer/right-sortable-src.js +28 -306
- data/app/assets/stylesheets/puffer/application.css +2 -0
- data/app/assets/stylesheets/puffer/file_input.css +59 -0
- data/app/assets/stylesheets/puffer/puffer.css +1 -0
- data/app/assets/stylesheets/puffer/puffer_grid.css +23 -0
- data/app/components/boolean/filter.html.erb +9 -0
- data/app/components/boolean_component.rb +4 -0
- data/app/components/carrierwave/form.html.erb +34 -0
- data/app/components/carrierwave/index.html.erb +6 -0
- data/app/components/carrierwave_component.rb +16 -0
- data/app/components/references_one/form.html.erb +2 -3
- data/app/controllers/admin/dashboard_controller.rb +0 -1
- data/app/controllers/admin/puffer_users_controller.rb +3 -7
- data/app/controllers/admin/sessions_controller.rb +1 -1
- data/app/models/puffer_user.rb +3 -18
- data/app/views/layouts/puffer.html.erb +2 -0
- data/app/views/puffer/base/_edit.html.erb +1 -1
- data/app/views/puffer/base/new.html.erb +1 -1
- data/app/views/puffer/grid_base/_grid.html.erb +9 -0
- data/app/views/puffer/grid_base/_index.html.erb +26 -0
- data/config/routes.rb +1 -1
- data/gemfiles/Gemfile-rails-3.1 +5 -0
- data/gemfiles/Gemfile-rails-3.1.lock +201 -0
- data/gemfiles/Gemfile-rails-3.2 +5 -0
- data/gemfiles/Gemfile-rails-3.2.lock +199 -0
- data/lib/puffer.rb +38 -12
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/base.rb +1 -2
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/dashboard_base.rb +0 -1
- data/lib/puffer/backends/controllers/grid_base.rb +12 -0
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/puffer_users_base.rb +0 -0
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/base.rb +0 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/clearance.rb +13 -5
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/devise.rb +1 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/simple.rb +1 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/tree_base.rb +0 -1
- data/lib/puffer/backends/models/user/active_record.rb +9 -0
- data/lib/puffer/backends/models/user/base.rb +30 -0
- data/lib/puffer/backends/models/user/mongoid.rb +15 -0
- data/lib/puffer/component.rb +2 -2
- data/lib/puffer/controller/auth.rb +48 -47
- data/lib/puffer/controller/config.rb +4 -6
- data/lib/puffer/controller/dsl.rb +2 -4
- data/lib/puffer/controller/mutate.rb +23 -26
- data/lib/puffer/extensions/directive_processor.rb +11 -16
- data/lib/puffer/extensions/engine.rb +7 -9
- data/lib/puffer/extensions/{mapper.rb → mapper31.rb} +10 -12
- data/lib/puffer/extensions/mapper32.rb +108 -0
- data/lib/puffer/filters.rb +15 -3
- data/lib/puffer/orm_adapter/active_record.rb +15 -2
- data/lib/puffer/orm_adapter/base.rb +4 -0
- data/lib/puffer/orm_adapter/mongoid.rb +15 -2
- data/lib/puffer/resource.rb +1 -1
- data/lib/puffer/version.rb +1 -1
- data/puffer.gemspec +10 -4
- data/spec/{app/components → components}/base_component_spec.rb +0 -0
- data/spec/{app/components → components}/boolean_component_spec.rb +0 -0
- data/spec/{app/components → components}/date_time_component_spec.rb +0 -0
- data/spec/{app/components → components}/file_component_spec.rb +0 -0
- data/spec/{app/components → components}/hidden_component_spec.rb +0 -0
- data/spec/{app/components → components}/password_component_spec.rb +0 -0
- data/spec/{app/components → components}/references_many_component_spec.rb +0 -0
- data/spec/{app/components → components}/references_one_component_spec.rb +0 -0
- data/spec/{app/components → components}/select_component_spec.rb +0 -0
- data/spec/{app/components → components}/string_component_spec.rb +0 -0
- data/spec/{app/components → components}/text_component_spec.rb +0 -0
- data/spec/controllers/sessions/base_shared.rb +66 -0
- data/spec/controllers/sessions/clearance_spec.rb +21 -0
- data/spec/controllers/sessions/simple_spec.rb +14 -0
- data/spec/dummy/app/controllers/admin/news_controller.rb +1 -1
- data/spec/dummy/app/controllers/admin/profiles_controller.rb +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/orms/mongoid_orm_primals_controller.rb +16 -0
- data/spec/dummy/app/helpers/news_helper.rb +1 -1
- data/spec/dummy/app/models/clearance_user.rb +3 -0
- data/spec/dummy/app/models/mongoid_orm/embeds_many_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/embeds_one_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/has_many_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/has_one_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/primal.rb +8 -0
- data/spec/dummy/app/models/profile.rb +2 -0
- data/spec/dummy/app/uploaders/avatar_uploader.rb +8 -0
- data/spec/dummy/config/application.rb +5 -3
- data/spec/dummy/config/initializers/clearance.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +34 -22
- data/spec/dummy/config/locales/devise.en.yml +6 -7
- data/spec/dummy/config/routes.rb +0 -1
- data/spec/dummy/db/migrate/{20100930133425_create_admin_profiles.rb → 20100930133425_create_profiles.rb} +2 -1
- data/spec/dummy/db/migrate/20111208222355_create_clearance_users.rb +13 -0
- data/spec/dummy/db/migrate/20120129091339_upgrade_clearance_to_diesel.rb +19 -0
- data/spec/dummy/db/schema.rb +12 -1
- data/spec/fabricators/clearance_user_fabricator.rb +4 -0
- data/spec/fabricators/puffer_user_fabricator.rb +5 -0
- data/spec/lib/filters_spec.rb +1 -1
- data/spec/lib/orm_adapter/active_record_spec.rb +0 -1
- data/spec/lib/orm_adapter/base_shared.rb +80 -76
- data/spec/lib/orm_adapter/mongoid_spec.rb +0 -2
- data/spec/lib/resource/tree_spec.rb +0 -1
- data/spec/spec_helper.rb +5 -3
- metadata +150 -75
- data/VERSION +0 -1
- data/app/models/puffer/puffer_user.rb +0 -25
@@ -0,0 +1,199 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/pyromaniac/work/opensource/puffer
|
3
|
+
specs:
|
4
|
+
puffer (0.1.0)
|
5
|
+
kaminari
|
6
|
+
orm_adapter
|
7
|
+
rails (~> 3.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionmailer (3.2.1)
|
13
|
+
actionpack (= 3.2.1)
|
14
|
+
mail (~> 2.4.0)
|
15
|
+
actionpack (3.2.1)
|
16
|
+
activemodel (= 3.2.1)
|
17
|
+
activesupport (= 3.2.1)
|
18
|
+
builder (~> 3.0.0)
|
19
|
+
erubis (~> 2.7.0)
|
20
|
+
journey (~> 1.0.1)
|
21
|
+
rack (~> 1.4.0)
|
22
|
+
rack-cache (~> 1.1)
|
23
|
+
rack-test (~> 0.6.1)
|
24
|
+
sprockets (~> 2.1.2)
|
25
|
+
activemodel (3.2.1)
|
26
|
+
activesupport (= 3.2.1)
|
27
|
+
builder (~> 3.0.0)
|
28
|
+
activerecord (3.2.1)
|
29
|
+
activemodel (= 3.2.1)
|
30
|
+
activesupport (= 3.2.1)
|
31
|
+
arel (~> 3.0.0)
|
32
|
+
tzinfo (~> 0.3.29)
|
33
|
+
activeresource (3.2.1)
|
34
|
+
activemodel (= 3.2.1)
|
35
|
+
activesupport (= 3.2.1)
|
36
|
+
activesupport (3.2.1)
|
37
|
+
i18n (~> 0.6)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
ammeter (0.2.2)
|
40
|
+
activesupport (>= 3.0)
|
41
|
+
railties (>= 3.0)
|
42
|
+
rspec (>= 2.2)
|
43
|
+
rspec-rails (>= 2.2)
|
44
|
+
arel (3.0.0)
|
45
|
+
bcrypt-ruby (3.0.1)
|
46
|
+
bson (1.5.2)
|
47
|
+
bson_ext (1.5.2)
|
48
|
+
bson (= 1.5.2)
|
49
|
+
builder (3.0.0)
|
50
|
+
capybara (1.1.2)
|
51
|
+
mime-types (>= 1.16)
|
52
|
+
nokogiri (>= 1.3.3)
|
53
|
+
rack (>= 1.0.0)
|
54
|
+
rack-test (>= 0.5.4)
|
55
|
+
selenium-webdriver (~> 2.0)
|
56
|
+
xpath (~> 0.1.4)
|
57
|
+
carrierwave (0.5.8)
|
58
|
+
activesupport (~> 3.0)
|
59
|
+
childprocess (0.3.0)
|
60
|
+
ffi (~> 1.0.6)
|
61
|
+
clearance (0.14.0)
|
62
|
+
diesel (~> 0.1.5)
|
63
|
+
rails (>= 3.0)
|
64
|
+
database_cleaner (0.7.1)
|
65
|
+
devise (2.0.0)
|
66
|
+
bcrypt-ruby (~> 3.0)
|
67
|
+
orm_adapter (~> 0.0.3)
|
68
|
+
railties (~> 3.1)
|
69
|
+
warden (~> 1.1)
|
70
|
+
diesel (0.1.5)
|
71
|
+
railties
|
72
|
+
diff-lcs (1.1.3)
|
73
|
+
erubis (2.7.0)
|
74
|
+
fabrication (1.2.0)
|
75
|
+
ffi (1.0.11)
|
76
|
+
forgery (0.5.0)
|
77
|
+
guard (1.0.0)
|
78
|
+
ffi (>= 0.5.0)
|
79
|
+
thor (~> 0.14.6)
|
80
|
+
guard-rspec (0.6.0)
|
81
|
+
guard (>= 0.10.0)
|
82
|
+
hike (1.2.1)
|
83
|
+
i18n (0.6.0)
|
84
|
+
journey (1.0.1)
|
85
|
+
json (1.6.5)
|
86
|
+
kaminari (0.13.0)
|
87
|
+
actionpack (>= 3.0.0)
|
88
|
+
activesupport (>= 3.0.0)
|
89
|
+
railties (>= 3.0.0)
|
90
|
+
libnotify (0.7.2)
|
91
|
+
mail (2.4.1)
|
92
|
+
i18n (>= 0.4.0)
|
93
|
+
mime-types (~> 1.16)
|
94
|
+
treetop (~> 1.4.8)
|
95
|
+
mime-types (1.17.2)
|
96
|
+
mini_magick (3.4)
|
97
|
+
subexec (~> 0.2.1)
|
98
|
+
mongo (1.5.2)
|
99
|
+
bson (= 1.5.2)
|
100
|
+
mongoid (2.4.3)
|
101
|
+
activemodel (~> 3.1)
|
102
|
+
mongo (~> 1.3)
|
103
|
+
tzinfo (~> 0.3.22)
|
104
|
+
multi_json (1.0.4)
|
105
|
+
nested_set (1.6.8)
|
106
|
+
activerecord (>= 3.0.0)
|
107
|
+
railties (>= 3.0.0)
|
108
|
+
nokogiri (1.5.0)
|
109
|
+
orm_adapter (0.0.6)
|
110
|
+
polyglot (0.3.3)
|
111
|
+
rack (1.4.1)
|
112
|
+
rack-cache (1.1)
|
113
|
+
rack (>= 0.4)
|
114
|
+
rack-ssl (1.3.2)
|
115
|
+
rack
|
116
|
+
rack-test (0.6.1)
|
117
|
+
rack (>= 1.0)
|
118
|
+
rails (3.2.1)
|
119
|
+
actionmailer (= 3.2.1)
|
120
|
+
actionpack (= 3.2.1)
|
121
|
+
activerecord (= 3.2.1)
|
122
|
+
activeresource (= 3.2.1)
|
123
|
+
activesupport (= 3.2.1)
|
124
|
+
bundler (~> 1.0)
|
125
|
+
railties (= 3.2.1)
|
126
|
+
railties (3.2.1)
|
127
|
+
actionpack (= 3.2.1)
|
128
|
+
activesupport (= 3.2.1)
|
129
|
+
rack-ssl (~> 1.3.2)
|
130
|
+
rake (>= 0.8.7)
|
131
|
+
rdoc (~> 3.4)
|
132
|
+
thor (~> 0.14.6)
|
133
|
+
rake (0.9.2.2)
|
134
|
+
rb-inotify (0.8.8)
|
135
|
+
ffi (>= 0.5.0)
|
136
|
+
rdoc (3.12)
|
137
|
+
json (~> 1.4)
|
138
|
+
rspec (2.8.0)
|
139
|
+
rspec-core (~> 2.8.0)
|
140
|
+
rspec-expectations (~> 2.8.0)
|
141
|
+
rspec-mocks (~> 2.8.0)
|
142
|
+
rspec-core (2.8.0)
|
143
|
+
rspec-expectations (2.8.0)
|
144
|
+
diff-lcs (~> 1.1.2)
|
145
|
+
rspec-mocks (2.8.0)
|
146
|
+
rspec-rails (2.8.1)
|
147
|
+
actionpack (>= 3.0)
|
148
|
+
activesupport (>= 3.0)
|
149
|
+
railties (>= 3.0)
|
150
|
+
rspec (~> 2.8.0)
|
151
|
+
rubyzip (0.9.5)
|
152
|
+
selenium-webdriver (2.18.0)
|
153
|
+
childprocess (>= 0.2.5)
|
154
|
+
ffi (~> 1.0.9)
|
155
|
+
multi_json (~> 1.0.4)
|
156
|
+
rubyzip
|
157
|
+
sprockets (2.1.2)
|
158
|
+
hike (~> 1.2)
|
159
|
+
rack (~> 1.0)
|
160
|
+
tilt (~> 1.1, != 1.3.0)
|
161
|
+
sqlite3 (1.3.5)
|
162
|
+
subexec (0.2.1)
|
163
|
+
thor (0.14.6)
|
164
|
+
tilt (1.3.3)
|
165
|
+
timecop (0.3.5)
|
166
|
+
treetop (1.4.10)
|
167
|
+
polyglot
|
168
|
+
polyglot (>= 0.3.1)
|
169
|
+
tzinfo (0.3.31)
|
170
|
+
warden (1.1.0)
|
171
|
+
rack (>= 1.0)
|
172
|
+
xpath (0.1.4)
|
173
|
+
nokogiri (~> 1.3)
|
174
|
+
|
175
|
+
PLATFORMS
|
176
|
+
ruby
|
177
|
+
|
178
|
+
DEPENDENCIES
|
179
|
+
ammeter
|
180
|
+
bson_ext
|
181
|
+
capybara
|
182
|
+
carrierwave
|
183
|
+
clearance
|
184
|
+
database_cleaner
|
185
|
+
devise
|
186
|
+
fabrication
|
187
|
+
forgery
|
188
|
+
guard
|
189
|
+
guard-rspec
|
190
|
+
libnotify
|
191
|
+
mini_magick
|
192
|
+
mongoid
|
193
|
+
nested_set
|
194
|
+
puffer!
|
195
|
+
rails (~> 3.2.0)
|
196
|
+
rb-inotify
|
197
|
+
rspec-rails
|
198
|
+
sqlite3
|
199
|
+
timecop
|
data/lib/puffer.rb
CHANGED
@@ -4,24 +4,49 @@ require 'orm_adapter'
|
|
4
4
|
require 'puffer/orm_adapter/base'
|
5
5
|
require 'puffer/orm_adapter/active_record' if defined?(ActiveRecord::Base::OrmAdapter)
|
6
6
|
require 'puffer/orm_adapter/mongoid' if defined?(Mongoid::Document::OrmAdapter)
|
7
|
-
#require 'puffer/orm_adapter/data_mapper' if defined?(DataMapper::Resource::OrmAdapter)
|
8
|
-
#require 'puffer/orm_adapter/mongo_mapper' if defined?(MongoMapper::Document::OrmAdapter)
|
7
|
+
# require 'puffer/orm_adapter/data_mapper' if defined?(DataMapper::Resource::OrmAdapter)
|
8
|
+
# require 'puffer/orm_adapter/mongo_mapper' if defined?(MongoMapper::Document::OrmAdapter)
|
9
9
|
|
10
10
|
require 'puffer/extensions/controller'
|
11
11
|
require 'puffer/extensions/core'
|
12
|
-
|
12
|
+
if Rails.version < '3.2'
|
13
|
+
require 'puffer/extensions/mapper31'
|
14
|
+
else
|
15
|
+
require 'puffer/extensions/mapper32'
|
16
|
+
end
|
13
17
|
require 'puffer/extensions/directive_processor'
|
14
18
|
require 'puffer/extensions/engine'
|
15
19
|
require 'puffer/engine'
|
16
20
|
|
17
21
|
module Puffer
|
18
22
|
|
23
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
|
24
|
+
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
|
25
|
+
|
19
26
|
class PufferError < StandardError
|
20
27
|
end
|
21
28
|
|
22
29
|
class ComponentMissing < PufferError
|
23
30
|
end
|
24
31
|
|
32
|
+
autoload :Base, 'puffer/backends/controllers/base'
|
33
|
+
autoload :TreeBase, 'puffer/backends/controllers/tree_base'
|
34
|
+
autoload :GridBase, 'puffer/backends/controllers/grid_base'
|
35
|
+
autoload :DashboardBase, 'puffer/backends/controllers/dashboard_base'
|
36
|
+
autoload :PufferUsersBase, 'puffer/backends/controllers/puffer_users_base'
|
37
|
+
|
38
|
+
module Sessions
|
39
|
+
autoload :Base, 'puffer/backends/controllers/sessions/base'
|
40
|
+
autoload :Simple, 'puffer/backends/controllers/sessions/simple'
|
41
|
+
autoload :Clearance, 'puffer/backends/controllers/sessions/clearance'
|
42
|
+
end
|
43
|
+
|
44
|
+
module User
|
45
|
+
autoload :Base, 'puffer/backends/models/user/base'
|
46
|
+
autoload :ActiveRecord, 'puffer/backends/models/user/active_record'
|
47
|
+
autoload :Mongoid, 'puffer/backends/models/user/mongoid'
|
48
|
+
end
|
49
|
+
|
25
50
|
module Controller
|
26
51
|
autoload :Action, 'puffer/controller/actions'
|
27
52
|
autoload :MemberAction, 'puffer/controller/actions'
|
@@ -32,9 +57,6 @@ module Puffer
|
|
32
57
|
autoload :Base, 'puffer/component'
|
33
58
|
end
|
34
59
|
|
35
|
-
# module Sessions
|
36
|
-
# end
|
37
|
-
|
38
60
|
# Puffer has two types of mappings. If maps <tt>field.type</tt> to component
|
39
61
|
# class and also maps field attributes to <tt>field.type</tt>
|
40
62
|
mattr_accessor :_component_mappings
|
@@ -99,24 +121,24 @@ module Puffer
|
|
99
121
|
end
|
100
122
|
|
101
123
|
append_custom_field_type :nested_attributes_one do |field|
|
102
|
-
field.reflection && field.reflection.macro
|
124
|
+
field.reflection && [:references_one, :has_one].include?(field.reflection.macro) && !field.reflection.through? && field.model.instance_methods.include?(:"#{field}_attributes=")
|
103
125
|
end
|
104
126
|
append_custom_field_type :nested_attributes_one do |field|
|
105
|
-
field.reflection && field.reflection.macro == :embeds_one
|
127
|
+
field.reflection && field.reflection.macro == :embeds_one
|
106
128
|
end
|
107
129
|
|
108
130
|
append_custom_field_type :nested_attributes_many do |field|
|
109
|
-
field.reflection && field.reflection.macro
|
131
|
+
field.reflection && [:references_many, :has_many].include?(field.reflection.macro) && !field.reflection.through? && field.model.instance_methods.include?(:"#{field}_attributes=")
|
110
132
|
end
|
111
133
|
append_custom_field_type :nested_attributes_many do |field|
|
112
|
-
field.reflection && field.reflection.macro == :embeds_many
|
134
|
+
field.reflection && field.reflection.macro == :embeds_many
|
113
135
|
end
|
114
136
|
|
115
137
|
append_custom_field_type :references_one do |field|
|
116
|
-
field.reflection && [:has_one, :belongs_to, :embedded_in].include?(field.reflection.macro)
|
138
|
+
field.reflection && [:has_one, :belongs_to, :references_one, :referenced_in, :embedded_in].include?(field.reflection.macro)
|
117
139
|
end
|
118
140
|
append_custom_field_type :references_many do |field|
|
119
|
-
field.reflection && [:has_many, :has_and_belongs_to_many].include?(field.reflection.macro)
|
141
|
+
field.reflection && [:has_many, :references_many, :has_and_belongs_to_many, :references_and_referenced_in_many].include?(field.reflection.macro)
|
120
142
|
end
|
121
143
|
|
122
144
|
append_custom_field_type :select do |field|
|
@@ -129,4 +151,8 @@ module Puffer
|
|
129
151
|
field.options.key? :render
|
130
152
|
end
|
131
153
|
|
154
|
+
append_custom_field_type :carrierwave do |field|
|
155
|
+
field.model.respond_to?(:uploaders) && field.model.uploaders.key?(field.name.to_sym)
|
156
|
+
end
|
157
|
+
|
132
158
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Puffer
|
2
2
|
class Base < ApplicationController
|
3
|
-
unloadable
|
4
3
|
pufferize!
|
5
4
|
|
6
5
|
before_filter :require_puffer_user
|
@@ -15,7 +14,7 @@ module Puffer
|
|
15
14
|
respond_to :html, :js
|
16
15
|
|
17
16
|
def index
|
18
|
-
@records = resource.collection.page(params[:page])
|
17
|
+
@records = resource.collection.page(params[:page]).per(puffer_filters.per_page)
|
19
18
|
respond_with @records
|
20
19
|
end
|
21
20
|
|
File without changes
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# implementation by default implemented basic auth through PufferUser.
|
3
3
|
# See Puffer::SessionsDeviseBase for alternative implementation example.
|
4
4
|
class Puffer::Sessions::Base < ApplicationController
|
5
|
-
unloadable
|
6
5
|
pufferize!
|
7
6
|
|
8
7
|
before_filter :require_puffer_user, :only => :destroy
|
@@ -2,6 +2,10 @@
|
|
2
2
|
# builder with the Clearance authentication & authorization solution.
|
3
3
|
class Puffer::Sessions::Clearance < Puffer::Sessions::Base
|
4
4
|
|
5
|
+
before_filter :if => :signed_in?, :except => :destroy do
|
6
|
+
redirect_to admin_root_url
|
7
|
+
end
|
8
|
+
|
5
9
|
setup do
|
6
10
|
model_name :user
|
7
11
|
end
|
@@ -11,13 +15,10 @@ class Puffer::Sessions::Clearance < Puffer::Sessions::Base
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def create
|
14
|
-
|
15
|
-
params[:session] = params.delete resource.attributes_key
|
16
|
-
|
17
|
-
if @record = authenticate(params) and sign_in(@record)
|
18
|
+
if @record = authenticate and sign_in(@record)
|
18
19
|
redirect_back_or admin_root_url
|
19
20
|
else
|
20
|
-
@record = resource.new_member :email =>
|
21
|
+
@record = resource.new_member :email => resource.attributes[:email]
|
21
22
|
render 'new'
|
22
23
|
end
|
23
24
|
end
|
@@ -26,4 +27,11 @@ class Puffer::Sessions::Clearance < Puffer::Sessions::Base
|
|
26
27
|
sign_out
|
27
28
|
redirect_to new_admin_session_url
|
28
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def authenticate
|
34
|
+
model.authenticate(resource.attributes[:email], resource.attributes[:password])
|
35
|
+
end
|
36
|
+
|
29
37
|
end
|
@@ -9,8 +9,8 @@ class Puffer::Sessions::Simple < Puffer::Sessions::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def create
|
12
|
-
p resource.attributes_key
|
13
12
|
@record = resource.adapter.find_first(:conditions => {:email => resource.attributes[:email]})
|
13
|
+
|
14
14
|
if @record && @record.authenticate(resource.attributes[:password])
|
15
15
|
session[:puffer_user_id] = @record.id
|
16
16
|
redirect_back_or admin_root_url
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Puffer
|
2
|
+
module User
|
3
|
+
module Base
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include ActiveModel::SecurePassword
|
8
|
+
|
9
|
+
attr_protected :password_digest
|
10
|
+
has_secure_password
|
11
|
+
|
12
|
+
validates :email, :uniqueness => true, :presence => true
|
13
|
+
validates :password, :presence => true, :length => { :minimum => 6 }, :on => :create
|
14
|
+
end
|
15
|
+
|
16
|
+
def roles= value
|
17
|
+
value = value.split(',').map(&:strip).map(&:presence) if value.is_a?(String)
|
18
|
+
write_attribute(:roles, value.join(', '))
|
19
|
+
end
|
20
|
+
|
21
|
+
def roles_array
|
22
|
+
roles.to_s.split(',').map(&:strip).map(&:presence)
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_role? role
|
26
|
+
roles_array.include?(role.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|