diff --git a/README.markdown b/README.markdown index a8bbff8..9b6a20b 100644 --- a/README.markdown +++ b/README.markdown @@ -64,3 +64,36 @@ class User < ActiveRecord::Base acts_as_authentic end ``` + +## Configuring authlogic + +We can also [configure various authlogic parameters](http://rdoc.info/github/binarylogic/authlogic/master/Authlogic/ActsAsAuthentic/Password/Config) using the ```acts_as_authentic``` method by giving it a block. For example, during testing, I disabled the password confirmation when I created a user in the rails console, just to make things easier. + +```ruby +acts_as_authentic do |c| + c.require_password_confirmation = false +end +``` + +## Creating our first user + +We'll do this manually, in ```rails c``` (the console). Since we configured away the confirmation password, all we need is to provide a login ID, an email, and a password. + +```ruby +pry(main)> User.create(:login => 'login1', :password => 'login1', :email => 'foo@bar.baz').save! +``` + +By default, authlogic requires an email address, and validates the password length. How can we change the required length? By using a configuration option as described above. The documentation lists the default, but let's use [Pry](https://github.com/pry/pry) to do a little spelunking. + +```ruby +pry(main)> cd User +pry(#):1> validates_length_of_password_field_options +=> {:minimum=>4, :if=>:require_password?} +pry(#):1> validates_format_of_email_field_options +=> {:with=>/^[A-Z0-9_\.%\+\-']+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i, + :message=>"should look like an email address."} + pry(#):1> validates_length_of_email_field_options + => {:maximum=>100} + ``` + +Note that the length validations accept the usual length validation options.