sparkly-auth 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +25 -0
- data/HISTORY.txt +7 -0
- data/README.rdoc +127 -1
- data/Rakefile +45 -13
- data/TODO +4 -0
- data/VERSION +1 -1
- data/app/controllers/sparkly_accounts_controller.rb +20 -13
- data/app/controllers/sparkly_controller.rb +5 -4
- data/app/controllers/sparkly_sessions_controller.rb +16 -9
- data/app/helpers/sparkly_accounts_helper.rb +2 -0
- data/app/helpers/sparkly_helper.rb +2 -0
- data/app/helpers/sparkly_sessions_helper.rb +2 -0
- data/app/models/remembrance_token.rb +3 -1
- data/app/views/sparkly_accounts/_rails2_form.html.erb +24 -0
- data/app/views/sparkly_accounts/_rails3_form.html.erb +26 -0
- data/app/views/sparkly_accounts/edit.html.erb +5 -23
- data/app/views/sparkly_accounts/new.html.erb +4 -23
- data/app/views/sparkly_sessions/_rails2_form.html.erb +22 -0
- data/app/views/sparkly_sessions/_rails3_form.html.erb +22 -0
- data/app/views/sparkly_sessions/new.html.erb +4 -21
- data/features/create_sparkly_account.feature +12 -0
- data/features/delete_sparkly_account.feature +12 -0
- data/features/edit_sparkly_account.feature +54 -0
- data/features/lock_abused_sparkly_account.feature +7 -0
- data/features/login_sparkly_session.feature +43 -0
- data/features/logout_sparkly_session.feature +16 -0
- data/features/setup/sparkly.rb +4 -0
- data/features/show_sparkly_account.feature +13 -0
- data/features/sparkly_session_timeout.feature +6 -0
- data/features/step_definitions/account/account_steps.rb +16 -0
- data/features/step_definitions/account/brief_steps.rb +9 -0
- data/features/step_definitions/debug_steps.rb +3 -0
- data/features/step_definitions/email_steps.rb +182 -0
- data/features/step_definitions/session/brief_steps.rb +0 -0
- data/features/step_definitions/session/logged_in_steps.rb +42 -0
- data/features/step_definitions/session/login_steps.rb +37 -0
- data/features/step_definitions/session/logout_steps.rb +5 -0
- data/features/step_definitions/session_steps.rb +16 -0
- data/features/step_definitions/sparkly_auth_steps.rb +0 -0
- data/features/step_definitions/web_steps.rb +287 -0
- data/features/support/env.rb +10 -0
- data/features/support/paths.rb +35 -0
- data/features/support/sparkly_helpers.rb +42 -0
- data/generators/sparkly/rails2.rb +79 -0
- data/generators/sparkly/rails3.rb +89 -0
- data/generators/sparkly/sparkly_generator.rb +4 -75
- data/generators/sparkly/templates/accounts_controller.rb +14 -13
- data/generators/sparkly/templates/accounts_helper.rb +1 -1
- data/generators/sparkly/templates/sessions_controller.rb +26 -12
- data/generators/sparkly/templates/sessions_helper.rb +1 -1
- data/generators/sparkly/templates/views/sparkly_accounts/_rails2_form.html.erb +24 -0
- data/generators/sparkly/templates/views/sparkly_accounts/_rails3_form.html.erb +26 -0
- data/generators/sparkly/templates/views/sparkly_accounts/edit.html.erb +5 -23
- data/generators/sparkly/templates/views/sparkly_accounts/new.html.erb +4 -23
- data/generators/sparkly/templates/views/sparkly_sessions/_rails2_form.html.erb +22 -0
- data/generators/sparkly/templates/views/sparkly_sessions/_rails3_form.html.erb +22 -0
- data/generators/sparkly/templates/views/sparkly_sessions/new.html.erb +4 -21
- data/lib/auth.rb +22 -1
- data/lib/auth/behavior/base.rb +25 -18
- data/lib/auth/behavior/base/configuration.rb +37 -0
- data/lib/auth/behavior/core.rb +22 -14
- data/lib/auth/behavior/core/authenticated_model_methods.rb +9 -1
- data/lib/auth/behavior/core/controller_extensions.rb +2 -2
- data/lib/auth/behavior/core/controller_extensions/class_methods.rb +1 -1
- data/lib/auth/behavior/core/password_methods.rb +5 -5
- data/lib/auth/behavior/remember_me.rb +7 -3
- data/lib/auth/behavior/remember_me/configuration.rb +8 -11
- data/lib/auth/behavior/remember_me/controller_extensions.rb +1 -1
- data/lib/auth/behavior_lookup.rb +4 -4
- data/lib/auth/builtin_behaviors.rb +3 -0
- data/lib/auth/configuration.rb +71 -25
- data/lib/auth/configuration/keys.rb +50 -0
- data/lib/auth/engine.rb +33 -0
- data/lib/auth/generators/views_generator.rb +13 -4
- data/lib/auth/model.rb +52 -22
- data/{init.rb → rails/hacks/rails2.rb} +1 -14
- data/rails/hacks/rails3.rb +22 -0
- data/rails/init.rb +7 -17
- data/rails/init_rails2.rb +39 -0
- data/rails/init_rails3.rb +2 -0
- data/rails/routes_rails3.rb +37 -0
- data/rake3 +1 -0
- data/rerun.txt +1 -0
- data/run_all_tests +1 -0
- data/sparkly-auth.gemspec +481 -23
- data/spec/behaviors/core/controller_extensions_spec.rb +49 -0
- data/spec/{lib/auth/behavior → behaviors}/core_spec.rb +29 -12
- data/spec/behaviors/remember_me/configuration_spec.rb +16 -0
- data/spec/behaviors/remember_me_spec.rb +167 -0
- data/spec/generators/sanity_checks_spec.rb +58 -0
- data/spec/lib/auth/configuration_spec.rb +61 -0
- data/spec/lib/auth/model_spec.rb +6 -9
- data/spec/lib/auth_spec.rb +2 -2
- data/spec/lib/hacks/rename_attributes_spec.rb +49 -0
- data/spec/routes_spec.rb +8 -2
- data/spec/spec2_helper.rb +52 -0
- data/spec/spec3_helper.rb +72 -0
- data/spec/spec_helper.rb +109 -49
- data/spec_env/rails2/README.1ST +23 -0
- data/spec_env/rails2/Rakefile +10 -0
- data/spec_env/rails2/app/controllers/application_controller.rb +13 -0
- data/spec_env/rails2/app/helpers/application_helper.rb +3 -0
- data/spec_env/rails2/app/models/user.rb +2 -0
- data/spec_env/rails2/app/views/application/not_found.html.erb +9 -0
- data/spec_env/rails2/app/views/layouts/application.html.erb +9 -0
- data/spec_env/rails2/config/boot.rb +110 -0
- data/spec_env/rails2/config/cucumber.yml +7 -0
- data/spec_env/rails2/config/database.yml +25 -0
- data/spec_env/rails2/config/environment.rb +46 -0
- data/spec_env/rails2/config/environments/cucumber.rb +35 -0
- data/spec_env/rails2/config/environments/development.rb +17 -0
- data/spec_env/rails2/config/environments/production.rb +28 -0
- data/spec_env/rails2/config/environments/test.rb +31 -0
- data/spec_env/rails2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec_env/rails2/config/initializers/inflections.rb +10 -0
- data/spec_env/rails2/config/initializers/mime_types.rb +5 -0
- data/spec_env/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/spec_env/rails2/config/initializers/session_store.rb +15 -0
- data/spec_env/rails2/config/initializers/sparkly_authentication.rb +30 -0
- data/spec_env/rails2/config/locales/en.yml +5 -0
- data/spec_env/rails2/config/routes.rb +46 -0
- data/spec_env/rails2/db/development.sqlite3 +0 -0
- data/spec_env/rails2/db/migrate/001_create_sparkly_passwords.rb +19 -0
- data/spec_env/rails2/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
- data/spec_env/rails2/db/migrate/003_add_confirmed_to_sparkly_passwords.rb +9 -0
- data/spec_env/rails2/db/migrate/20100607103543_create_users.rb +12 -0
- data/spec_env/rails2/db/migrate/20100609152058_add_email_to_users.rb +9 -0
- data/spec_env/rails2/db/schema.rb +42 -0
- data/spec_env/rails2/db/seeds.rb +7 -0
- data/spec_env/rails2/db/test.sqlite3 +0 -0
- data/spec_env/rails2/doc/README_FOR_APP +2 -0
- data/spec_env/rails2/doc/sparkly_authentication.txt +56 -0
- data/spec_env/rails2/features/support/env.rb +58 -0
- data/spec_env/rails2/lib/tasks/cucumber.rake +47 -0
- data/spec_env/rails2/lib/tasks/rspec.rake +144 -0
- data/spec_env/rails2/lib/tasks/sparkly_migration.rb +1 -0
- data/spec_env/rails2/log/cucumber.log +8412 -0
- data/spec_env/rails2/log/development.log +317 -0
- data/spec_env/rails2/log/test.log +32053 -0
- data/spec_env/rails2/public/404.html +30 -0
- data/spec_env/rails2/public/422.html +30 -0
- data/spec_env/rails2/public/500.html +30 -0
- data/spec_env/rails2/public/favicon.ico +0 -0
- data/spec_env/rails2/public/images/rails.png +0 -0
- data/spec_env/rails2/public/javascripts/application.js +2 -0
- data/spec_env/rails2/public/javascripts/controls.js +963 -0
- data/spec_env/rails2/public/javascripts/dragdrop.js +973 -0
- data/spec_env/rails2/public/javascripts/effects.js +1128 -0
- data/spec_env/rails2/public/javascripts/prototype.js +4320 -0
- data/spec_env/rails2/public/robots.txt +5 -0
- data/spec_env/rails2/rerun.txt +1 -0
- data/spec_env/rails2/script/about +4 -0
- data/spec_env/rails2/script/autospec +6 -0
- data/spec_env/rails2/script/console +3 -0
- data/spec_env/rails2/script/cucumber +10 -0
- data/spec_env/rails2/script/dbconsole +3 -0
- data/spec_env/rails2/script/destroy +3 -0
- data/spec_env/rails2/script/generate +3 -0
- data/spec_env/rails2/script/performance/benchmarker +3 -0
- data/spec_env/rails2/script/performance/profiler +3 -0
- data/spec_env/rails2/script/plugin +3 -0
- data/spec_env/rails2/script/runner +3 -0
- data/spec_env/rails2/script/server +3 -0
- data/spec_env/rails2/script/spec +10 -0
- data/spec_env/rails2/spec/controllers/sparkly_user_sessions_controller_spec.rb +10 -0
- data/spec_env/rails2/spec/rcov.opts +2 -0
- data/spec_env/rails2/spec/spec.opts +4 -0
- data/spec_env/rails2/spec/spec_helper.rb +54 -0
- data/spec_env/rails2/test/fixtures/users.yml +7 -0
- data/spec_env/rails2/test/performance/browsing_test.rb +9 -0
- data/spec_env/rails2/test/test_helper.rb +38 -0
- data/spec_env/rails2/test/unit/user_test.rb +8 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/.specification +63 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/generators/sparkly/sparkly_generator.rb +1 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/lib/sparkly-auth-bootstrap.rb +6 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/rails/init.rb +1 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/sparkly-auth-bootstrap.gemspec +55 -0
- data/spec_env/rails3/.gitignore +4 -0
- data/spec_env/rails3/Gemfile +43 -0
- data/spec_env/rails3/Gemfile.lock +124 -0
- data/spec_env/rails3/README +256 -0
- data/spec_env/rails3/Rakefile +7 -0
- data/spec_env/rails3/app/controllers/application_controller.rb +6 -0
- data/spec_env/rails3/app/helpers/application_helper.rb +2 -0
- data/spec_env/rails3/app/models/user.rb +3 -0
- data/spec_env/rails3/app/views/application/not_found.html.erb +9 -0
- data/spec_env/rails3/app/views/layouts/application.html.erb +22 -0
- data/spec_env/rails3/config.ru +4 -0
- data/spec_env/rails3/config/application.rb +47 -0
- data/spec_env/rails3/config/boot.rb +13 -0
- data/spec_env/rails3/config/cucumber.yml +8 -0
- data/spec_env/rails3/config/database.yml +28 -0
- data/spec_env/rails3/config/environment.rb +5 -0
- data/spec_env/rails3/config/environments/development.rb +22 -0
- data/spec_env/rails3/config/environments/production.rb +49 -0
- data/spec_env/rails3/config/environments/spec.rb +35 -0
- data/spec_env/rails3/config/environments/test.rb +43 -0
- data/spec_env/rails3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec_env/rails3/config/initializers/inflections.rb +10 -0
- data/spec_env/rails3/config/initializers/mime_types.rb +5 -0
- data/spec_env/rails3/config/initializers/secret_token.rb +7 -0
- data/spec_env/rails3/config/initializers/session_store.rb +8 -0
- data/spec_env/rails3/config/initializers/sparkly_authentication.rb +30 -0
- data/spec_env/rails3/config/locales/en.yml +5 -0
- data/spec_env/rails3/config/routes.rb +61 -0
- data/spec_env/rails3/db/migrate/001_create_sparkly_passwords.rb +19 -0
- data/spec_env/rails3/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
- data/spec_env/rails3/db/migrate/20100810132843_create_users.rb +13 -0
- data/spec_env/rails3/db/schema.rb +42 -0
- data/spec_env/rails3/db/seeds.rb +7 -0
- data/spec_env/rails3/doc/README_FOR_APP +2 -0
- data/spec_env/rails3/doc/sparkly_authentication.txt +56 -0
- data/spec_env/rails3/features/support/env.rb +62 -0
- data/spec_env/rails3/lib/sparkly/bootstrap.rb +1 -0
- data/spec_env/rails3/lib/tasks/.gitkeep +0 -0
- data/spec_env/rails3/lib/tasks/cucumber.rake +53 -0
- data/spec_env/rails3/lib/tasks/sparkly_migration.rb +1 -0
- data/spec_env/rails3/public/404.html +26 -0
- data/spec_env/rails3/public/422.html +26 -0
- data/spec_env/rails3/public/500.html +26 -0
- data/spec_env/rails3/public/favicon.ico +0 -0
- data/spec_env/rails3/public/images/rails.png +0 -0
- data/spec_env/rails3/public/javascripts/application.js +2 -0
- data/spec_env/rails3/public/javascripts/controls.js +965 -0
- data/spec_env/rails3/public/javascripts/dragdrop.js +974 -0
- data/spec_env/rails3/public/javascripts/effects.js +1123 -0
- data/spec_env/rails3/public/javascripts/prototype.js +6001 -0
- data/spec_env/rails3/public/javascripts/rails.js +175 -0
- data/spec_env/rails3/public/robots.txt +5 -0
- data/spec_env/rails3/public/stylesheets/.gitkeep +0 -0
- data/spec_env/rails3/script/cucumber +10 -0
- data/spec_env/rails3/script/rails +6 -0
- data/spec_env/rails3/test/fixtures/users.yml +7 -0
- data/spec_env/rails3/test/performance/browsing_test.rb +9 -0
- data/spec_env/rails3/test/test_helper.rb +13 -0
- data/spec_env/rails3/test/unit/user_test.rb +8 -0
- data/spec_env/rails3/vendor/plugins/.gitkeep +0 -0
- data/spec_env/rails3/webrat.log +5 -0
- metadata +393 -15
- data/dependencies.rb +0 -1
- data/spec/lib/auth/behavior/remember_me_spec.rb +0 -127
- data/spec/lib/auth/extensions/controller_spec.rb +0 -32
@@ -0,0 +1,79 @@
|
|
1
|
+
class SparklyGenerator < Rails::Generator::NamedBase
|
2
|
+
def source_root
|
3
|
+
File.join(File.dirname(__FILE__), 'templates')
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(args, options = {}) #:nodoc:
|
7
|
+
@options = options
|
8
|
+
unless args.empty?
|
9
|
+
which = args.first
|
10
|
+
@type = which.downcase
|
11
|
+
args << "generic" if nameless_type?
|
12
|
+
end
|
13
|
+
super(args, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def manifest
|
17
|
+
record do |m|
|
18
|
+
case @type
|
19
|
+
when *nameless_types then send(@type, m)
|
20
|
+
else raise ArgumentError, "Expected type to be one of #{nameless_types.to_sentence(:connector => 'or ')}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def help(m)
|
27
|
+
m.directory 'doc'
|
28
|
+
m.file 'help_file.txt', 'doc/sparkly_authentication.txt'
|
29
|
+
logger.log '', File.read(File.join(File.dirname(__FILE__), 'templates/help_file.txt'))
|
30
|
+
logger.quiet = true # we plan to tell the user the file has been saved, so why tell them twice?
|
31
|
+
end
|
32
|
+
|
33
|
+
def controllers(m)
|
34
|
+
spawn_model_generator(m, Auth::Generators::ControllersGenerator)
|
35
|
+
end
|
36
|
+
|
37
|
+
def routes(m)
|
38
|
+
spawn_model_generator(m, Auth::Generators::RouteGenerator)
|
39
|
+
end
|
40
|
+
|
41
|
+
def views(m)
|
42
|
+
spawn_model_generator(m, Auth::Generators::ViewsGenerator)
|
43
|
+
end
|
44
|
+
|
45
|
+
def migrations(m)
|
46
|
+
spawn_model_generator(m, Auth::Generators::MigrationGenerator)
|
47
|
+
end
|
48
|
+
|
49
|
+
def config(m)
|
50
|
+
spawn_generator(m, Auth::Generators::ConfigurationGenerator, [])
|
51
|
+
end
|
52
|
+
|
53
|
+
def spawn_model_generator(manifest, type)
|
54
|
+
each_model do |model|
|
55
|
+
spawn_generator(manifest, type, model)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def spawn_generator(manifest, type, args)
|
60
|
+
generator = type.new(args, spawned_generator_options)
|
61
|
+
generator.manifest.replay(manifest)
|
62
|
+
end
|
63
|
+
|
64
|
+
def each_model(&block)
|
65
|
+
Auth.configuration.authenticated_models.each &block
|
66
|
+
end
|
67
|
+
|
68
|
+
def nameless_type?
|
69
|
+
nameless_types.include? @type
|
70
|
+
end
|
71
|
+
|
72
|
+
def nameless_types
|
73
|
+
%w(migrations config help views controllers)
|
74
|
+
end
|
75
|
+
|
76
|
+
def spawned_generator_options
|
77
|
+
options.merge(:source => File.join(source_root), :destination => destination_root)
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class SparklyGenerator < Rails::Generators::NamedBase
|
4
|
+
class << self
|
5
|
+
def source_root
|
6
|
+
File.join(File.dirname(__FILE__), "templates")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def do_generation
|
11
|
+
method_name = "gen_#{file_name.pluralize}"
|
12
|
+
if private_methods.collect { |m| m.to_s }.include?(method_name) # why doesn't respond_to? work?!
|
13
|
+
send method_name
|
14
|
+
else
|
15
|
+
puts "(not found: #{method_name})"
|
16
|
+
gen_helps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def gen_controllers
|
22
|
+
each_model do |model|
|
23
|
+
@model = model
|
24
|
+
template "accounts_controller.rb", File.join("app/controllers", "#{model.accounts_controller.underscore}_controller.rb"),
|
25
|
+
:assigns => { :model => model }
|
26
|
+
template "sessions_controller.rb", File.join("app/controllers", "#{model.sessions_controller.underscore}_controller.rb"),
|
27
|
+
:assigns => { :model => model }
|
28
|
+
|
29
|
+
template "accounts_helper.rb", File.join("app/helpers", "#{model.accounts_controller.underscore}_helper.rb"),
|
30
|
+
:assigns => { :model => model }
|
31
|
+
template "sessions_helper.rb", File.join("app/helpers", "#{model.sessions_controller.underscore}_helper.rb"),
|
32
|
+
:assigns => { :model => model }
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Controller generator should also kick off the corresponding view generation.
|
37
|
+
gen_views
|
38
|
+
end
|
39
|
+
|
40
|
+
def gen_helps # yeah, yeah...
|
41
|
+
copy_file 'help_file.txt', 'doc/sparkly_authentication.txt'
|
42
|
+
readme 'help_file.txt'
|
43
|
+
end
|
44
|
+
|
45
|
+
def gen_configs
|
46
|
+
copy_file "tasks/migrations.rb", "lib/tasks/sparkly_migration.rb"
|
47
|
+
copy_file 'initializer.rb', 'config/initializers/sparkly_authentication.rb'
|
48
|
+
end
|
49
|
+
|
50
|
+
def gen_migrations
|
51
|
+
mg_version = 0
|
52
|
+
Auth.behavior_classes.each do |behavior|
|
53
|
+
behavior.migrations.each do |file_name|
|
54
|
+
fn_with_ext = file_name[/\.([^\.]+)$/] ? file_name : "#{file_name}.rb"
|
55
|
+
mg_version += 1
|
56
|
+
mg_version_s = mg_version.to_s.rjust(3, '0')
|
57
|
+
template File.join("migrations", fn_with_ext), File.join("db/migrate/#{mg_version_s}_#{fn_with_ext}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def gen_views
|
63
|
+
each_model do |model|
|
64
|
+
@model = model
|
65
|
+
resource_directory = File.join("app/views", model.accounts_controller.underscore)
|
66
|
+
sessions_directory = File.join("app/views", model.sessions_controller.underscore)
|
67
|
+
|
68
|
+
base = File.join(self.class.source_root, "views/sparkly_accounts")
|
69
|
+
Dir[File.join(base, "**/*")].each do |fi|
|
70
|
+
fi.gsub!(/^#{Regexp::escape base}/, '')
|
71
|
+
copy_file(File.join("views/sparkly_accounts", fi), File.join(resource_directory, fi))
|
72
|
+
end
|
73
|
+
|
74
|
+
base = File.join(self.class.source_root, "views/sparkly_sessions")
|
75
|
+
Dir[File.join(base, "**/*")].each do |fi|
|
76
|
+
fi.gsub!(/^#{Regexp::escape base}/, '')
|
77
|
+
copy_file(File.join("views/sparkly_sessions", fi), File.join(sessions_directory, fi))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def models
|
83
|
+
Auth.configuration.authenticated_models
|
84
|
+
end
|
85
|
+
|
86
|
+
def each_model(&block)
|
87
|
+
models.each &block
|
88
|
+
end
|
89
|
+
end
|
@@ -1,76 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
unless args.empty?
|
6
|
-
which = args.first
|
7
|
-
@type = which.downcase
|
8
|
-
args << "generic" if nameless_type?
|
9
|
-
end
|
10
|
-
super(args, options)
|
11
|
-
end
|
12
|
-
|
13
|
-
def manifest
|
14
|
-
record do |m|
|
15
|
-
case @type
|
16
|
-
when *nameless_types then send(@type, m)
|
17
|
-
else raise ArgumentError, "Expected type to be one of #{nameless_types.to_sentence(:connector => 'or ')}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def help(m)
|
24
|
-
m.directory 'doc'
|
25
|
-
m.file 'help_file.txt', 'doc/sparkly_authentication.txt'
|
26
|
-
logger.log '', File.read(File.join(File.dirname(__FILE__), 'templates/help_file.txt'))
|
27
|
-
logger.quiet = true # we plan to tell the user the file has been saved, so why tell them twice?
|
28
|
-
end
|
29
|
-
|
30
|
-
def controllers(m)
|
31
|
-
spawn_model_generator(m, Auth::Generators::ControllersGenerator)
|
32
|
-
end
|
33
|
-
|
34
|
-
def routes(m)
|
35
|
-
spawn_model_generator(m, Auth::Generators::RouteGenerator)
|
36
|
-
end
|
37
|
-
|
38
|
-
def views(m)
|
39
|
-
spawn_model_generator(m, Auth::Generators::ViewsGenerator)
|
40
|
-
end
|
41
|
-
|
42
|
-
def migrations(m)
|
43
|
-
spawn_model_generator(m, Auth::Generators::MigrationGenerator)
|
44
|
-
end
|
45
|
-
|
46
|
-
def config(m)
|
47
|
-
spawn_generator(m, Auth::Generators::ConfigurationGenerator, [])
|
48
|
-
end
|
49
|
-
|
50
|
-
def spawn_model_generator(manifest, type)
|
51
|
-
each_model do |model|
|
52
|
-
spawn_generator(manifest, type, model)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def spawn_generator(manifest, type, args)
|
57
|
-
generator = type.new(args, spawned_generator_options)
|
58
|
-
generator.manifest.replay(manifest)
|
59
|
-
end
|
60
|
-
|
61
|
-
def each_model(&block)
|
62
|
-
Auth.configuration.authenticated_models.each &block
|
63
|
-
end
|
64
|
-
|
65
|
-
def nameless_type?
|
66
|
-
nameless_types.include? @type
|
67
|
-
end
|
68
|
-
|
69
|
-
def nameless_types
|
70
|
-
%w(migrations config help views controllers)
|
71
|
-
end
|
72
|
-
|
73
|
-
def spawned_generator_options
|
74
|
-
options.merge(:source => File.join(source_root), :destination => destination_root)
|
75
|
-
end
|
1
|
+
if Rails::VERSION::MAJOR == 2
|
2
|
+
require File.join(File.dirname(__FILE__), 'rails2')
|
3
|
+
else
|
4
|
+
require File.join(File.dirname(__FILE__), 'rails3')
|
76
5
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class <%=model.accounts_controller.camelize%>Controller < SparklyController
|
1
|
+
class <%=(@model || model).accounts_controller.camelize%>Controller < SparklyController
|
2
2
|
require_login_for :show, :edit, :update, :destroy
|
3
3
|
|
4
4
|
# GET new_model_url
|
@@ -7,9 +7,9 @@ class <%=model.accounts_controller.camelize%>Controller < SparklyController
|
|
7
7
|
|
8
8
|
# POST model_url
|
9
9
|
def create
|
10
|
-
if model.save
|
11
|
-
login!(model)
|
12
|
-
redirect_back_or_default
|
10
|
+
if model.save
|
11
|
+
login!(model) if sparkly_config.login_after_signup
|
12
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.account_created_message
|
13
13
|
else
|
14
14
|
render :action => 'new'
|
15
15
|
end
|
@@ -31,7 +31,7 @@ class <%=model.accounts_controller.camelize%>Controller < SparklyController
|
|
31
31
|
end
|
32
32
|
|
33
33
|
if model.save
|
34
|
-
redirect_back_or_default user_path,
|
34
|
+
redirect_back_or_default user_path, sparkly_config.account_updated_message
|
35
35
|
else
|
36
36
|
render :action => 'edit'
|
37
37
|
end
|
@@ -42,24 +42,25 @@ class <%=model.accounts_controller.camelize%>Controller < SparklyController
|
|
42
42
|
current_user && current_user.destroy
|
43
43
|
logout!
|
44
44
|
@current_user = nil
|
45
|
-
flash[:notice] =
|
46
|
-
redirect_back_or_default
|
45
|
+
flash[:notice] = sparkly_config.account_deleted_message
|
46
|
+
redirect_back_or_default sparkly_config.default_destination
|
47
47
|
end
|
48
48
|
|
49
49
|
protected
|
50
50
|
def find_user_model
|
51
51
|
# password fields are protected attrs, so we need to exclude them then add them explicitly.
|
52
|
-
self.model_instance = current_user ||
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
self.model_instance = current_user || begin
|
53
|
+
model = model_class.new(model_params.without(:password, :password_confirmation))
|
54
|
+
model.password = model_params[:password]
|
55
|
+
model.password_confirmation = model_params[:password_confirmation]
|
56
|
+
model
|
57
|
+
end
|
57
58
|
end
|
58
59
|
|
59
60
|
# Uncomment if you don't trust the params[:model] set up by Sparkly routing, or if you've
|
60
61
|
# disabled them.
|
61
62
|
#
|
62
63
|
#def model_name
|
63
|
-
# <%=model.name.inspect%>
|
64
|
+
# <%=(@model || model).name.inspect%>
|
64
65
|
#end
|
65
66
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module <%=model.accounts_controller.camelize%>Helper
|
1
|
+
module <%=(@model || model).accounts_controller.camelize%>Helper
|
2
2
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
class <%=model.sessions_controller.camelize%>Controller < SparklyController
|
1
|
+
class <%=(@model || model).sessions_controller.camelize%>Controller < SparklyController
|
2
|
+
require_logout_for :new, :create
|
3
|
+
|
2
4
|
# GET new_model_session_url
|
3
5
|
def new
|
4
6
|
end
|
5
7
|
|
6
8
|
# POST model_session_url
|
7
9
|
def create
|
8
|
-
if session[:locked_out_at] && session[:locked_out_at] >
|
9
|
-
flash[:error] =
|
10
|
+
if session[:locked_out_at] && session[:locked_out_at] > sparkly_config.account_lock_duration.ago
|
11
|
+
flash[:error] = sparkly_config.account_locked_message
|
10
12
|
render :action => 'new'
|
11
13
|
return
|
12
14
|
end
|
@@ -15,15 +17,15 @@ class <%=model.sessions_controller.camelize%>Controller < SparklyController
|
|
15
17
|
:include => :passwords)
|
16
18
|
|
17
19
|
if model && model.password_matches?(model_params[:password])
|
18
|
-
login! model
|
19
|
-
redirect_back_or_default
|
20
|
+
login! model, :remember => remember_me?
|
21
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.login_successful_message
|
20
22
|
else
|
21
23
|
session[:login_failures] = session[:login_failures].to_i + 1
|
22
|
-
if
|
24
|
+
if sparkly_config.max_login_failures && session[:login_failures] >= sparkly_config.max_login_failures
|
23
25
|
session[:locked_out_at] = Time.now
|
24
|
-
flash[:error] =
|
26
|
+
flash[:error] = sparkly_config.account_locked_message
|
25
27
|
else
|
26
|
-
flash[:error] =
|
28
|
+
flash[:error] = sparkly_config.invalid_credentials_message
|
27
29
|
end
|
28
30
|
render :action => "new"
|
29
31
|
end
|
@@ -31,15 +33,27 @@ class <%=model.sessions_controller.camelize%>Controller < SparklyController
|
|
31
33
|
|
32
34
|
# DELETE model_session_url
|
33
35
|
def destroy
|
34
|
-
logout!
|
35
|
-
redirect_back_or_default
|
36
|
+
logout!(:forget => true)
|
37
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.logout_message
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
private
|
39
41
|
# Uncomment if you don't trust the params[:model] set up by Sparkly routing, or if you've
|
40
42
|
# disabled them.
|
41
43
|
#
|
42
44
|
#def model_name
|
43
|
-
# <%=model.name.inspect%>
|
45
|
+
# <%=(@model || model).name.inspect%>
|
44
46
|
#end
|
47
|
+
|
48
|
+
def remember_me?
|
49
|
+
remembrance = model_params[:remember_me]
|
50
|
+
if remembrance.kind_of?(String)
|
51
|
+
return false if remembrance.blank?
|
52
|
+
return remembrance.to_i != 0
|
53
|
+
elsif remembrance.kind_of?(Numeric)
|
54
|
+
return remembrance != 0
|
55
|
+
else
|
56
|
+
return remembrance
|
57
|
+
end
|
58
|
+
end
|
45
59
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module <%=model.sessions_controller.camelize%>Helper
|
1
|
+
module <%=(@model || model).sessions_controller.camelize%>Helper
|
2
2
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%form_for model, :url => model_path do |f|%>
|
2
|
+
<p>
|
3
|
+
<%=f.error_messages%>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<%=f.label model_config.key%><br/>
|
8
|
+
<%=f.text_field model_config.key%>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%=f.label :password%><br/>
|
13
|
+
<%=f.password_field :password, :value => ''%>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<%=f.label :password_confirmation%><br/>
|
18
|
+
<%=f.password_field :password_confirmation, :value => ''%>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<%=f.submit(model.new_record? ? "Sign up" : "Update Profile")%>
|
23
|
+
</p>
|
24
|
+
<%end%>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%=form_for model, :url => model_path do |f|%>
|
2
|
+
<p>
|
3
|
+
<%model.errors.each do |error, message|%>
|
4
|
+
<%=error.to_s.titleize%> <%=message%>
|
5
|
+
<%end%>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<%=f.label model_config.key%><br/>
|
10
|
+
<%=f.text_field model_config.key%>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<%=f.label :password%><br/>
|
15
|
+
<%=f.password_field :password, :value => ''%>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<p>
|
19
|
+
<%=f.label :password_confirmation%><br/>
|
20
|
+
<%=f.password_field :password_confirmation, :value => ''%>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<%=f.submit(model.new_record? ? "Sign up" : "Update Profile")%>
|
25
|
+
</p>
|
26
|
+
<%end%>
|