Plugin details

Simple authentication/acl system for rails

Websitehttp://happiness-is-slavery.net/ Repositorygit://github.com/andreashappe/blubber.git Author Andreas Happe Tags ACL LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/andreashappe/blubber.git

Example
=======

There's one rake task to generate a simple session_controller. Use rake blubber::create_session_controller and add the following to your config/routes.rb:

    map.resource :session
    map.login 'login', :controller => "sessions", :action => "new"


Then create a normal HTML form to submit the login data (e.g. in HAML):

- form_tag :controller => :sessions, :action => "create" do
  %p
    %label{:for => :email} Email
    = text_field_tag :email, nil, :size => 20
  %p
    %label{:for => :password} Kennwort
    = password_field_tag :password, nil, :size => 20
  %p.submit= submit_tag 'Login'


"I want to make UserController#index available to all users. UserController#new and #create should be available to anyone to allow them to login. The rest should only be available to the owner":
in UserController:

  # if someone does a GET request on /users/ we will need
  # to know if he is the owner of the viewed resource
  def prepare(user, params)
    @viewed_user = params[:id] if params.include?(:id)
  end

  def acl_anonymous
    [:new, :create]
  end

  def acl_user
    [:index]
  end

  # check if the currently logged in user (current_user) is
  # looking at his own page, if so make him :moderator
  def role_for(user)
    if @viewed_user then
      return :moderator i @viewed_user.id == current_user.id
    end
    return :user
  end


in the User model:

  # for this example just use a simple testing account, real
  # implementations should check the password against a hashed
  # field in the database
  def authenticate(email, password)
    if email == "andy@snikt.net" && password == "fubar" then
      return true
    else
      return false
    end
  end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago