public
Description: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/restful-authentication.git
Click here to lend your support to: restful-authentication and make a donation at www.pledgie.com !
Add in support for AASM
codafoo (author)
Tue Jun 03 05:36:17 -0700 2008
commit  2d24dae056f4d2b68c69429ed4395cdd8b02efb2
tree    28aae697675b9ba0eafaf664cd966d367bc34772
parent  cff7cbca33d3d1c10f219a7628539712e62bda93
0
...
122
123
124
 
 
125
126
127
...
122
123
124
125
126
127
128
129
0
@@ -122,6 +122,8 @@ To use:
0
   @--skip-migration@ will skip the user migration, and @--skip-routes@ will skip
0
   resource generation -- both useful if you've already run this generator.
0
 
0
+* --aasm: Works the same as stateful but uses the updated aasm gem
0
+
0
 * --rspec: Generate RSpec tests and Stories in place of standard rails tests.
0
   This requires the
0
     "RSpec and Rspec-on-rails plugins":http://rspec.info/
...
268
269
270
271
 
 
 
 
 
272
273
274
...
386
387
388
 
 
389
390
391
...
268
269
270
 
271
272
273
274
275
276
277
278
...
390
391
392
393
394
395
396
397
0
@@ -268,7 +268,11 @@ class AuthenticatedGenerator < Rails::Generator::NamedBase
0
         puts "- Add an observer to config/environment.rb"
0
         puts " config.active_record.observers = :#{file_name}_observer"
0
       end
0
- if options[:stateful]
0
+ if options[:aasm]
0
+ puts "- Install the acts_as_state_machine gem:"
0
+ puts " sudo gem sources -a http://gems.github.com (If you haven't already)"
0
+ puts " sudo gem install rubyist-aasm"
0
+ elsif options[:stateful]
0
         puts "- Install the acts_as_state_machine plugin:"
0
         puts " svn export http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk vendor/plugins/acts_as_state_machine"
0
       end
0
@@ -386,6 +390,8 @@ protected
0
       "Generate signup 'activation code' confirmation via email") { |v| options[:include_activation] = true }
0
     opt.on("--stateful",
0
       "Use acts_as_state_machine. Assumes --include-activation") { |v| options[:include_activation] = options[:stateful] = true }
0
+ opt.on("--aasm",
0
+ "Use (gem) aasm. Assumes --include-activation") { |v| options[:include_activation] = options[:stateful] = options[:aasm] = true }
0
     opt.on("--rspec",
0
       "Force rspec mode (checks for RAILS_ROOT/spec by default)") { |v| options[:rspec] = true }
0
     opt.on("--no-rspec",
...
4
5
6
7
 
 
 
8
9
10
11
12
...
4
5
6
 
7
8
9
10
 
11
12
13
0
@@ -4,9 +4,10 @@ class <%= class_name %> < ActiveRecord::Base
0
   include Authentication
0
   include Authentication::ByPassword
0
   include Authentication::ByCookieToken
0
-<% if options[:stateful] -%>
0
+<% if options[:aasm] -%>
0
+ include Authorization::AasmRoles
0
+<% elsif options[:stateful] -%>
0
   include Authorization::StatefulRoles<% end %>
0
-
0
   validates_presence_of :login
0
   validates_length_of :login, :within => 3..40
0
   validates_uniqueness_of :login, :case_sensitive => false

Comments

  • jerome Tue Jun 10 08:11:54 -0700 2008

    The init.rb file misses then a:

    require File.dirname(FILE) + ’/lib/authorization/aasm_roles’

  • jerome Tue Jun 10 08:54:14 -0700 2008

    White the aasm gem, I guess the generator should write

    find_by_login_and_state(login, ‘active’)
    instead of find_by_login

    and add a require ‘aasm’ to the model if—aasm option is set

  • jerome Tue Jun 10 08:56:39 -0700 2008

    acts_as_dyslexic : with the aasm gem…

  • codafoo Tue Jun 10 09:26:18 -0700 2008

    1. aasm_roles isn’t included by the model not required by the init.rb
    2. Your right, I need to adjust it for find_by_state if aasm.
    3. I don’t require it in the model because I assume you vendored aasm, or require it in the init.
    4. ?

  • jerome Tue Jun 10 16:35:31 -0700 2008

    1. So what if—aasm is set ?
    3. Ok. It would be good then to add it in the README. Note also that the acts_as_state_machine is only available in the former SVN trunk. The rubyst github account has updated it.
    4. 2 sodas please

  • dpowell Tue Jun 10 16:37:40 -0700 2008

    config.gem “rubyist-aasm”, :lib => “aasm”, :source => “http://gems.github.com” in your config initializer for Rails 2.1.

  • jerome Tue Jun 10 17:08:32 -0700 2008

    Oh another thing in the StatefulRolesInstanceMethods: the do_activate instance method isn’t called upon the activate! , I don’t understand why. Calling user.do_activate works of course.

  • DrMark Sun Jun 15 14:36:41 -0700 2008

    Where is the bug tracker for restful_authentication? This code doesn’t work properly on Rails 2.1. The make_activation_code fires twice when you create a new user. The first time, the record is a new record and the activation code is set. The second time, the record has already been saved and the activation code is RESET. Thus the validation email contains the wrong validation code. I have a sample app at DrMark/skeleton if anyone wants to take a look. Also, I fixed it (temporarily) by adding a check for new_record? to the make_activation_code function.

  • codafoo Sun Jun 15 16:19:11 -0700 2008

    jerome,

    For item #2 the stateful option wraps the find in a find_in_state so it does check the state of the user.

  • wgpubs Tue Jun 24 17:21:00 -0700 2008

    Issues:
    1. When User is created the record is properly updated from ‘passive’ to ‘pending’ BUT the “make_activation_code is not called as expected given => :make_activation_code.” I had to put a before_filter in my User class to call “make_activation_code” to get things to work.

    2. Same problem when moving from ‘pending’ to ‘active’. The state is changed when user.activate! is called … but the “do_activate” method is not called.

    What gives? Am I missing something???

    Thanks

  • minofare Mon Jul 14 08:16:04 -0700 2008

    Whenever you are trying to make the activation code try removing the enter command and pasting this in:

    aasm_event :register, :success => :make_activation_code do

    If you do it on the event block, it appears to fire the method correctly. I found this in the rspec tests of the aasm code. You should take a look for more examples.