No commit activity in last 3 years
No release in over 3 years
Provides super simple authentication al a Ryan Bates old screen cast. Creates admin access feature which allows for a single password login for admin tool access.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 1.2.9

Runtime

 Project Readme

Super Simple Admin README

Super Simple Authentication is a gem which makes it super easy to encapsulate the behavior of the Ryan Bates screen cast on super simple authentication.

This is still very fresh off the press, so any and all feedback is greatly appreciated.

Basic Usage

Firstly, install the gem by running

sudo gem install super_simple_admin

You’ll have to make sure that gemcutter is listed in your gem sources.

In your ApplicationController do

class ApplicationController
	include SuperSimpleAdmin::ApplicationController
end

Create a sessions controller that looks like this

class SessionsController < ApplicationController
	include SuperSimpleAdmin::SessionsController
end

Now create a app/views/sessions/new.html.haml file (you are using haml, aren’t you?) that looks something like this

#login_form
	%p
		- form_tag sessions_path do
			= label_tag :password, "Password:"
			= password_field_tag :password
			= submit_tag "Submit"

You can now use the admin? helper method in any of your views to change what website users see based on whether they are logged in and also use authorize in before filters in your controllers to restrict access as you see fit.

Oh – and one last thing. You’ll also want to add some routes in your routes.rb file for the sessions_path to work, as well as for nice login route so that the /login and /logout paths do what you would expect.

And that’s it!

Customization, configuration and defaults

So you’re probably wondering how to customize this bugger. There are two easy ways to do this, and both are perfectly acceptable are interoperable. However, there are defaults for everything so that you can get up and running without having to think. You’ll obviously at least want to set your own password once in production though.

Hash access

The innards of this gem refer to the SuperSimpleAdmin.config hash for all of the configurable settings. As such (by way of example), you can specify or access settings like this

SuperSimpleAdmin.config[:password] = "verysecret"
SuperSimpleAdmin.config[:password] == params[:password]

Cake right?

Configuration file

When the parent SuperSimpleAdmin module is loaded it looks to see if there is a admin_config.yml file in your config directory and if there is loads it up for you. Anything set here will override gem defaults. This is only loaded once though, which means you can still use hash access later on in your code to modify config parameters (as above).

Environment independent settings are specified within all_environments, while environment specific setting are set within RAILS_ENV as below

all_environments:
	password: somewhatsecret
	unauthorization_message: "You are not authorized to view this page"
production:
	password: verysecret

Defaults

The default options are as follows

SuperSimpleAdmin.config = {
  :password => "secret",
  :unauthorized_message => "Unauthorized access",
  :unauthorized_redirect => "/",
  :login_success_message => "Successfully logged in",
  :login_success_redirect => "/",
  :login_failure_message => "Incorrect password",
  :login_failure_redirect => "/sessions/new",
  :logout_message => "Logout successful",
  :logout_redirect => "/"
}

TODO

These are the ideas I have for improvements. If you feel inspired to help with any of them, fork and send a request. I’d especially appreciate help with speccing, as I’m still pretty new to speccing out gems.

  • Want to have a generator for the new sessions page.
  • Consider if there is a way to be more supportive of gems like cancan
  • Auto setup of login and logout routes
  • Specs (sorry – when this was started, I didn’t know how to spec rails gems, and I haven’t had time yet to go back and spec)
  • Cucumber steps for logging in
  • An install rake task which maybe sets up the routes as well as the config file.

Fixes

  • Seem to be having trouble specifying :login_failure_message from the config file (fixed – 02/14)