PRESENTING AUTHLOUNGE

(no more maintained, sorry)

Working on a new awesome project I decide to start using CouchDB to persist data. Also I found the Authlogic rails gem/plugin really well done and very flexible.

To connect to CouchDB I forked Couchrest that allow to save objects in couchdb from Rails.

Basically the challenge was to remove ActiveRecord dependencies and glue to Couchrest. I found some features and shortcuts that ActiveRecord has that wasn’t available at Couchrest that I believe are useful like property_names (similar to column_names in ActiveRecord), the uniqueness validator and the _changed? method with the changed_properties hash.

I added those shortcuts and features to couchrest and reconnect every point that persist data to couchrest.

I have to keep out the authenticates_many and the scope feature due that they are based on ActiveRecord.

This is experimental for now.

Which are the differences?

First at all you can remove ActiveRecord from your environment.rb.

As read in the environment.rb comment: Skip frameworks you’re not going to use. To use Rails without a database relational database, you must remove the Active Record framework.

  config.frameworks -= [ :active_record]

Here is an example how your User model should be:

class User < CouchRest::ExtendedDocument
  include CouchRest::Validation
  include CouchRest::Callbacks

  use_database SERVER.default_database

  property :login                   # optional, you can use email instead, or both
  property :email                   # optional, you can use login instead, or both
  property :crypted_password        # optional, see below
  property :password_salt           # optional, but highly recommended
  property :persistence_token       # required
  property :single_access_token     # optional, see Authlogic::Session::Params
  property :perishable_token        # optional, see Authlogic::Session::Perishability

  # Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
  property :login_count, :type => Integer           # optional, see Authlogic::Session::MagicColumns
  property :failed_login_count, :type => Integer    # optional, see Authlogic::Session::MagicColumns
  property :last_request_at, :cast_as => 'Time'       # optional, see Authlogic::Session::MagicColumns
  property :current_login_at, :cast_as => 'Time'      # optional, see Authlogic::Session::MagicColumns
  property :last_login_at, :cast_as => 'Time'         # optional, see Authlogic::Session::MagicColumns
  property :current_login_ip       # optional, see Authlogic::Session::MagicColumns
  property :last_login_ip        # optional, see Authlogic::Session::MagicColumns

  timestamps!

  def self.default_timezone
    :utc
  end

  acts_as_authentic

end

No changes on controllers.

I will continue working on this, making oauth and openid work too. (I didn’t see if some changes are necessary yet)

Thanks

© copyright. All rights reserved. Pedro Visintin