Created
June 13, 2010 14:42
Revisions
-
KevinTriplett revised this gist
Jan 30, 2010 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class User < ActiveRecord::Base c.merge_validates_format_of_email_field_options({:unless => :skip_email_validation}) c.merge_validates_uniqueness_of_email_field_options({:unless => :skip_email_validation}) ### password: only validate if user is active ### authlogic minimum defaults to 4, our system is not as critical :) c.merge_validates_confirmation_of_password_field_options({:unless => :inactive?}) c.merge_validates_length_of_password_field_options({:unless => :inactive?, :minimum => 3}) c.merge_validates_length_of_password_confirmation_field_options({:unless => :inactive?, :minimum => 3}) -
KevinTriplett revised this gist
Jan 30, 2010 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,24 @@ class User < ActiveRecord::Base # gradual engagement is needed, to allow admin creation of users # users should create authorization data only when they need to # access some system feature that requires authentication # So ... our gradual engagement scheme for authlogic: # 1. admin creates user, setting only name and phone number (required) # admin may set email address (optional) # 2. user is sent email invitation with link to activate their account # admin can re-send email at user's request # 3. user sets login and password/password_confirmation using activation form # #active attribute set true in controller #create method # note: cannot use :if condition since authlogic uses them # fatal flaw: will break any authlogic :unless condition # fortunately, authlogic currently does not use the :unless condition acts_as_authentic do |c| ### email: only validate if primary_email present c.email_field = :primary_email c.merge_validates_length_of_email_field_options({:unless => :skip_email_validation}) c.merge_validates_format_of_email_field_options({:unless => :skip_email_validation}) c.merge_validates_uniqueness_of_email_field_options({:unless => :skip_email_validation}) ### password: only validate if user is active c.merge_validates_confirmation_of_password_field_options({:unless => :inactive?}) c.merge_validates_length_of_password_field_options({:unless => :inactive?, :minimum => 3}) c.merge_validates_length_of_password_confirmation_field_options({:unless => :inactive?, :minimum => 3}) -
KevinTriplett revised this gist
Jan 30, 2010 . 1 changed file with 20 additions and 41 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,51 +5,30 @@ class User < ActiveRecord::Base # 2. user is then sent invitation to activate their account # 3. user#active is set true by hidden field on activation form where # the user sets their login and password # cannot use :if condition since authlogic uses them # fatal flaw: will break any authlogic :unless condition # (fortunately, authlogic currently does not use the :unless condition) acts_as_authentic do |c| ### email: only validate if email is present c.email_field = :primary_email c.merge_validates_length_of_email_field_options({:unless => :skip_email_validation}) c.merge_validates_format_of_email_field_options({:unless => :skip_email_validation}) c.merge_validates_uniqueness_of_email_field_options({:unless => :skip_email_validation}) ### password: only validate if user is active (require_password? is authlogic method) c.merge_validates_confirmation_of_password_field_options({:unless => :inactive?}) c.merge_validates_length_of_password_field_options({:unless => :inactive?, :minimum => 3}) c.merge_validates_length_of_password_confirmation_field_options({:unless => :inactive?, :minimum => 3}) ### login: only validate if user is active c.merge_validates_length_of_login_field_options({:unless => :inactive?}) c.merge_validates_format_of_login_field_options({:unless => :inactive?}) c.merge_validates_uniqueness_of_login_field_options({:unless => :inactive?}) end def inactive? !active end def skip_email_validation !attribute_present?('primary_email') end end -
KevinTriplett revised this gist
Jan 30, 2010 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,14 +26,14 @@ class User < ActiveRecord::Base }) ### password: only validate if user is active (require_password? is authlogic method) c.validates_length_of_password_field_options({ :if => Proc.new {|user| user.active? && user.send(:require_password?)}, :minimum => 3 }) c.validates_confirmation_of_password_field_options({ :if => Proc.new {|user| user.active? && user.send(:require_password?)} }) c.validates_length_of_password_confirmation_field_options({ :if => Proc.new {|user| user.active? && user.send(:require_password?)}, :minimum => 3 }) ### login: only validate if user is active -
KevinTriplett revised this gist
Jan 30, 2010 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,30 +11,30 @@ class User < ActiveRecord::Base ### email: only validate if email is present c.email_field = :primary_email c.validates_length_of_email_field_options({ :if => Proc.new {|user| user.attribute_present?('primary_email')}, :within => 6..100 }) c.validates_format_of_email_field_options({ :if => Proc.new {|user| user.attribute_present?('primary_email')}, :with => Authlogic::Regex.email, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.") }) c.validates_uniqueness_of_email_field_options({ :if => Proc.new {|user| user.attribute_present?('primary_email') && user.primary_email_changed?}, :case_sensitive => false, :scope => validations_scope }) ### password: only validate if user is active (require_password? is authlogic method) c.validates_length_of_password_field_options({ :if => Proc.new {|user| user.active? && user.require_password?}, :minimum => 3 }) c.validates_confirmation_of_password_field_options({ :if => Proc.new {|user| user.active? && user.require_password?} }) c.validates_length_of_password_confirmation_field_options({ :if => Proc.new {|user| user.active? && user.require_password?}, :minimum => 3 }) ### login: only validate if user is active c.validates_length_of_login_field_options({ @@ -47,7 +47,7 @@ class User < ActiveRecord::Base :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.") }) c.validates_uniqueness_of_login_field_options({ :if => Proc.new {|user| user.active? && user.login_changed?}, :case_sensitive => false, :scope => validations_scope }) -
KevinTriplett created this gist
Jan 30, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ class User < ActiveRecord::Base # gradual engagement scheme for authlogic: # 1. user is created by admin, only name and phone number required # admin may set email address (primary_email) at creation # 2. user is then sent invitation to activate their account # 3. user#active is set true by hidden field on activation form where # the user sets their login and password # authlogic options pulled out and explicitly set here so that it is # visible and so that :if conditional statements can be merged acts_as_authentic do |c| ### email: only validate if email is present c.email_field = :primary_email c.validates_length_of_email_field_options({ :if => :email_field_present?, :within => 6..100 }) c.validates_format_of_email_field_options({ :if => :email_field_present?, :with => Authlogic::Regex.email, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.") }) c.validates_uniqueness_of_email_field_options({ :if => :email_field_present_and_primary_email_changed?, :case_sensitive => false, :scope => validations_scope }) ### password: only validate if user is active c.validates_length_of_password_field_options({ :if => :active_and_require_password?, :minimum => 4 }) c.validates_confirmation_of_password_field_options({ :if => :active_and_require_password? }) c.validates_length_of_password_confirmation_field_options({ :if => :active_and_require_password?, :minimum => 4 }) ### login: only validate if user is active c.validates_length_of_login_field_options({ :if => :active?, :within => 3..100 }) c.validates_format_of_login_field_options({ :if => :active?, :with => Authlogic::Regex.login, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.") }) c.validates_uniqueness_of_login_field_options({ :if => :active_and_login_changed?, :case_sensitive => false, :scope => validations_scope }) end end