Login, Signup
We are presented with these quick forms all the time. While it is easy to create standard login and signup pages, Amazon.com has a good one:
What makes it good?
First of all, the prompts are written in plain English. Amazon sells to a wide slice of the population, meaning that about 15% of their customers are probably not very technology-saavy. (-2?) Anything they can do to ease the operation helps their customers buy.
Secondly, when a user visits Amazon.com, there is only one link: “Your account” instead of separate login and signup links. Simple is generally better.
Also note the standard “forgot your password” link plus an additional “has your email address changed?” question. Both are useful to have close at hand.
Implementation
Rails 2.0 strongly encourages you to design RESTful applications. Login forms are associated with Session objects, while signup forms go with User objects (rather, Brewer objects in our case). A simple redirect in the SessionsController#create method takes care of pointing a user in the right direction.
class SessionsController < ApplicationController def create if params[:signin_action] == 'new_user' redirect_to new_brewer_path( :brewer => {:email => params[:email]} ) else # Do sigin stuff end end end |
Note that we pass params[:email] to the new_brewer_path so that field is automatically populated on the next page. If you are using the generated scaffold, you will have to change your BrewersController#new method to instantiate a new @brewer object:
class BrewersController < ApplicationController def new @brewer = Brewer.new(params[:brewer]) end end |
Lastly, here is the extra test:
class SessionsControllerTest < Test::Unit::TestCase def test_should_redirect_to_new_brewer_if_asked an_email = "dean@brewsession.com" post :create, :email => an_email, :signin_action => 'new_user' assert_redirected_to new_brewer_path(:brewer => {:email => an_email} ) assert_nil session[:brewer_id] end end |
In a later post I will talk about how to implement the change password action in a RESTful way.
–Dean