Skip to content

Commit

Permalink
More docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
davelnewton committed Sep 4, 2011
1 parent 2751594 commit 758b764
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.markdown
Expand Up @@ -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(#<Class:0x1041dcc20>):1> validates_length_of_password_field_options
=> {:minimum=>4, :if=>:require_password?}
pry(#<Class:0x1041dcc20>):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(#<Class:0x1041dcc20>):1> validates_length_of_email_field_options
=> {:maximum=>100}
```

Note that the length validations accept the usual length validation options.

0 comments on commit 758b764

Please sign in to comment.