/sociopathor

Social features in a rails engine

Primary LanguageRubyOtherNOASSERTION

# What ?

Sociopathor is a rails engine that bundle ready to use implementation of authlogic
and authlogic-connect, to register / login on your app with facebook and twitter.
Once installed, the only thing you need to do is to give your api keys and secrets.

I created it in order not to have to recode this each times, so I only put in the
services I needed (twitter and facebook) among the large panel of services supported
by authlogic.

If you need more sociopathy, well, fork it.


# Install

In your Gemfile, put :
  gem 'sociopathor', :git => 'git://github.com/oelmekki/sociopathor.git'

Then run :
  bundle install
  rails generate sociopathor:install
  rake db:migrate


# Config

Sociopathor use authlogic-connect, and should be configured as that one.
Two files will be installed :
  config/authlogic.yml
  config/initializers/authlogic_connect_config.rb

Enter your api key / secrets in both.


# Use

Sociopathor gives you two ApplicationController methods to use with filters :
- require_user : redirect to login page if user isn't logged in
- require_no_user : redirect to root page and inform user she should not be logged in

He also gives you three helpers methods :
- store_location : store the current url in order to redirect back to it then
- redirect_back_or_default : redirect to stored location or to default given as parameter
- current_user : retrieve the current user instance (or nil)

The User model give you following methods :
- twitter_restful : proxy to twitter api ( or nil if user is not logged in with twitter )
- facebook_restful : proxy to facebook api ( or nil if user is not logged in with facebook )
- profile : a hash containing profile for default (first connected) third party service :
  * id : the user id at third party
  * name : the name of user at third party
  * avatar : the user avatar
  * link : the user profile url at third party

Finally, he also gives you the following routes (not sot antisocial, after all):
- /login
- /logout


# Extend

You'll probably want to extend the base classes. Sociopathor being a rails engine, you
can't just monkey patch them : if an app/models/user.rb file exists in your app, the
engine's one won't be loaded.

That's ok, this mechanism let you override views. Sociopathor generator installs a
bunch of files for you to extend its base class :
  app/models/local_user.rb
  app/models/local_user_session.rb
  app/controllers/local_users_controller.rb
  app/controllers/local_user_sessions_controller.rb

If you don't need them, you can safely erase them.