Rails plugin for creating special cookies to setup automatic logins with Tender
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 21 commits behind courtenay:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/tender
rails
tasks
test
MIT-LICENSE
README
Rakefile
install.rb

README

Tender MultiPass
===============

Easily add auto-login cookie values for Tender (http://tenderapp.com)

Setup
=====

* Install the plugin, and include the Tender::MultiPassMethods into your user model
* Set up these 3 values:  Tender::MultiPass.site_key, 
  Tender::MultiPass.cookie_domain, and Tender::MultiPass.support_domain
* Use @user.tender_multipass(cookies) to modify cookies inside your controller request.

* More info: http://help.tenderapp.com/faqs/setup-installation/login-from-cookies

Example (Rails)
=======

# /config/initializers/tender_multi_pass.rb
Tender::MultiPass.class_eval do
  self.site_key       = "abc"
  self.support_domain = "help.xoo.com"
  self.cookie_domain  = ".xoo.com"
end

# /app/models/user.rb
class User < ActiveRecord::Base
  include Tender::MultiPassMethods
end

# /app/controllers/sessions_controller.rb
class SessionsController
  def login
    if user = User.authenticate(params[:login], params[:password])
      user.tender_multipass(cookies, 1.week.from_now.to_i)
    end
    redirect_to "/"
  end
end

You can also set the user's name, instead of using their email address as the key.  Set the name of the field 
as the final parameter.

  user.tender_multipass(cookies, 1.week.from_now.to_i, :full_name)

If you want to have Tender redirect to your site's login form and can't/don't want to use domain cookies you
can just pass the variables in the URL. 
  
  Tender -> click "login" -> goes to your site -> returns to Tender with URL params
  
Your login action should also check to see if the user is already logged in, so you can just bounce them back to Tender.
You can implement this something like:

# /app/controllers/sessions_controller.rb
class SessionsController
  def login
    if logged_in? || current_user = User.authenticate(params[:login], params[:password])
      if params[:tender]
        auth = current_user.tender_multipass({}, 1.week.from_now.to_i)
        redirect_to "http://your.tenderapp.com/login?email=#{auth[:tender_email][:value]}&expires=#{auth[:tender_expires][:value]}&hash=#{auth[:tender_hash][:value]}"
      else
        redirect_to "/"
      end
    end
  end
end


Notes
=====

* It is assumed User#email is available
* When testing, you must use strings rather than symbols to check for the cookies

  assert_equal ['hello@example.com'], response.cookies['tender_email']

Copyright (c) 2008-* rick olson, released under the MIT license