Topic: Deployment and initial admin authentication.

When deploying a Rails application that will be administered by a special user, how does one go about initializing this initial admin?

I would like to create a website that is administered by one special user.  This user will be able to login, manage users and content, etc...  But, when deploying a website, this administrator will not exist yet.  How does one properly deploy a website and then initialize this first admin user before anyone else can use the application/website?

Re: Deployment and initial admin authentication.

I use restful_authentication (RA),  but I think there are other more popular Plugins now.  I think this would work with any Plugin.

If you ship your site to someone else who then is responsible for initializing it and setting up the users table,  you could just ship it with an empty users table.  Then you could do this in the application_controller:

def index
  if User.find(1)
    render :action=>:index  #display your normal index (main) page
  else
    redirect_to (:controller=>:users, :action=>:new, :type=>:admin)
  end
end

In the case of RA,  which doesn't come out of the box (or didn't 3+ years ago) with roles,  you could just extend the users table to use Single Table Inheritance, i.e add a type attribute to the User model.

Make sure that for normal users you always pass :type=>:user,  and the only place where :type is set to :admin,  is when the user table is Empty.

From then on,  you check if a signed in user has admin privileges, you could do

if current_user.class == Admin

current_user is the RA method for accessing the currently logged on user,  other authentication plugigs will have the same or a similar method.  Other Plugins may support Roles,  so instead of hacking RA to use STI,  you would utilize Roles in the plugin,  but the concept is pretty much the same.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Deployment and initial admin authentication.

I just initialize my initial user (I call it manager) from a migration.  I have in development created a user with the initial password I want and I just plug the user and the encryption of the password into the proper place in the database.  Then I have to tell the user in the clear what the initial user/password is and tell them to change it.

Re: Deployment and initial admin authentication.

Thanks, guys.  This has pointed me in the right direction.