jeremydurham-restful_authentication 1.1.5 → 1.1.6

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.
@@ -244,11 +244,20 @@ class AuthenticatedGenerator < Rails::Generator::NamedBase
244
244
  unless options[:skip_routes]
245
245
  # Note that this fails for nested classes -- you're on your own with setting up the routes.
246
246
  m.route_resource controller_singular_name
247
- m.route_resources model_controller_plural_name
247
+ if options[:stateful]
248
+ m.route_resources model_controller_plural_name, :member => { :suspend => :put,
249
+ :unsuspend => :put,
250
+ :purge => :delete }
251
+ else
252
+ m.route_resources model_controller_plural_name
253
+ end
248
254
  m.route_name('signup', '/signup', {:controller => model_controller_plural_name, :action => 'new'})
249
255
  m.route_name('register', '/register', {:controller => model_controller_plural_name, :action => 'create'})
250
256
  m.route_name('login', '/login', {:controller => controller_controller_name, :action => 'new'})
251
257
  m.route_name('logout', '/logout', {:controller => controller_controller_name, :action => 'destroy'})
258
+ if options[:include_activation]
259
+ m.route_name('activate', '/activate/:activation_code', { :controller => model_controller_plural_name, :action => 'activate', :activation_code => nil })
260
+ end
252
261
  end
253
262
  end
254
263
 
@@ -11,13 +11,28 @@ Rails::Generator::Commands::Create.class_eval do
11
11
  end
12
12
  end
13
13
 
14
+ def route_resources(*resources)
15
+ resource_options = resources.last.is_a?(Hash) ? resources.pop : nil
16
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
17
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
18
+
19
+ resource_list << ", #{resource_options.inspect}" if resource_options
20
+ logger.route "map.resources #{resource_list}"
21
+ unless options[:pretend]
22
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
23
+ "#{match}\n map.resources #{resource_list}\n"
24
+ end
25
+ end
26
+ end
27
+
14
28
  def route_name(name, path, route_options = {})
15
29
  sentinel = 'ActionController::Routing::Routes.draw do |map|'
16
30
 
17
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
31
+ routing_options = route_options.map { |k,v| ":#{k} => '#{v}'" }.join(', ')
32
+ logger.route "map.#{name} '#{path}', #{routing_options}"
18
33
  unless options[:pretend]
19
34
  gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
20
- "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
35
+ "#{match}\n map.#{name} '#{path}', #{routing_options}"
21
36
  end
22
37
  end
23
38
  end
@@ -1,26 +1,24 @@
1
1
  class <%= migration_name %> < ActiveRecord::Migration
2
2
  def self.up
3
- create_table "<%= table_name %>", :force => true do |t|
4
- t.column :login, :string, :limit => 40
5
- t.column :name, :string, :limit => 100, :default => '', :null => true
6
- t.column :email, :string, :limit => 100
7
- t.column :crypted_password, :string, :limit => 40
8
- t.column :salt, :string, :limit => 40
9
- t.column :created_at, :datetime
10
- t.column :updated_at, :datetime
11
- t.column :remember_token, :string, :limit => 40
12
- t.column :remember_token_expires_at, :datetime
3
+ create_table :<%= table_name %>, :force => true do |t|
4
+ t.string :login, :crypted_password, :salt, :remember_token, :limit => 40
5
+ t.datetime :remember_token_expires_at
6
+ t.string :name, :limit => 100, :default => '', :null => true
7
+ t.string :email, :limit => 100
13
8
  <% if options[:include_activation] -%>
14
- t.column :activation_code, :string, :limit => 40
15
- t.column :activated_at, :datetime<% end %>
9
+ t.string :activation_code, :limit => 40
10
+ t.datetime :activated_at
11
+ <% end -%>
16
12
  <% if options[:stateful] -%>
17
- t.column :state, :string, :null => :no, :default => 'passive'
18
- t.column :deleted_at, :datetime<% end %>
13
+ t.string :state, :null => :no, :default => 'passive'
14
+ t.datetime :deleted_at
15
+ <% end -%>
16
+ t.timestamps
19
17
  end
20
18
  add_index :<%= table_name %>, :login, :unique => true
21
19
  end
22
20
 
23
21
  def self.down
24
- drop_table "<%= table_name %>"
22
+ drop_table :<%= table_name %>
25
23
  end
26
24
  end
@@ -22,20 +22,29 @@ class <%= model_controller_class_name %>Controller < ApplicationController
22
22
  success = @<%= file_name %> && @<%= file_name %>.save
23
23
  <% end -%>
24
24
  if success && @<%= file_name %>.errors.empty?
25
- <% if !options[:include_activation] -%>
25
+ <% if !options[:include_activation] -%>
26
26
  # Protects against session fixation attacks, causes request forgery
27
27
  # protection if visitor resubmits an earlier form using back
28
28
  # button. Uncomment if you understand the tradeoffs.
29
29
  # reset session
30
30
  self.current_<%= file_name %> = @<%= file_name %> # !! now logged in
31
31
  <% end -%>redirect_back_or_default('/')
32
+ <% if options[:include_activation] -%>
32
33
  flash[:notice] = "Thanks for signing up! We're sending you an email with your activation code."
34
+ <% else -%>
35
+ flash[:notice] = "Thanks for signing up!"
36
+ <% end -%>
33
37
  else
34
- flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
38
+ <% if options[:include_activation] -%>
39
+ flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
40
+ <% else -%>
41
+ flash[:error] = "We couldn't create your account, sorry."
42
+ <% end -%>
35
43
  render :action => 'new'
36
44
  end
37
45
  end
38
- <% if options[:include_activation] %>
46
+
47
+ <% if options[:include_activation] -%>
39
48
  def activate
40
49
  logout_keeping_session!
41
50
  <%= file_name %> = <%= class_name %>.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
@@ -52,7 +61,9 @@ class <%= model_controller_class_name %>Controller < ApplicationController
52
61
  redirect_back_or_default('/')
53
62
  end
54
63
  end
55
- <% end %><% if options[:stateful] %>
64
+ <% end -%>
65
+
66
+ <% if options[:stateful] -%>
56
67
  def suspend
57
68
  @<%= file_name %>.suspend!
58
69
  redirect_to <%= model_controller_routing_name %>_path
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jeremydurham-restful_authentication}
5
- s.version = "1.1.5"
5
+ s.version = "1.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["RailsJedi", "Rick Olson"]
9
- s.date = %q{2009-11-30}
9
+ s.date = %q{2009-12-09}
10
10
  s.description = %q{This widely-used plugin provides a foundation for securely managing user.}
11
11
  s.email = %q{railsjedi@gmail.com}
12
12
  s.extra_rdoc_files = ["README.textile"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremydurham-restful_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RailsJedi
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-30 00:00:00 -05:00
13
+ date: 2009-12-09 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency