Where, when and how to create the administrator account/user for a private website?
So what I am asking is what's the preferable technique for creating that first administrator account/user. In my case it's for a private webapplication. I am talking about the account/user that will own the application and will if needed create/promote the other administrators. I guess you can this guy the root user?
Here are a few ways I encountered in other websites/webapplication.
You see this a lot in blog software or forums. When you install the application it will ask you to create an administrator user. Private webapplication will most likely not have this.
A file you run to install your application. This file will create the administrator account for you.
A configuration file that holds the credentials for the administrator account.
Manually insert it into a database:
Manually insert the administrator info into the database.
On a bootstrapping phase. Someone has suggested seeds.rb. I personally prefer to use the bootstrapper gem (with some addtions that allow me to parse csv files).
This action allows you to create a rake task which can be invoked like this:
This will create the initial admin user, as well as any seeding data (such as the list of countries, or a default blog format, etc). The script is very flexible. You can make it ask for a password, or accept a password parameter, if you feel like it.
In all cases I use declarative_authorization in order to manage user permissions.
Your admin user must return a role called 'admin' (or whatever name you choose) on the list of roles attached to it. I usually have 1 single role per user, mainly because I can use role inheritance (e.g. admins are also editors by default). This means that on my database I've got a single field for users called "role_id". 0 is usually for the admin role, since it is the first one created.
A specific file inside db/bootstrap/users.rb (or yaml, or csv) specifies the details of a user with the admin role activated. The
rake db:boostrap order parses that file and creates the user accordingly.