 Path    = require('path')
 Read    = require('read')
 Async   = require('async')
+User    = require('./user')
 MongoInterface = require('./mongo_interface')
 {hashPassword} = require('../api/utils')
 

                                (next) ->
                                    configureUser(next)
                                (adminUser, next) ->
                                    serverConfig.admins.push(adminUser)
                                    writeConfigToFile()
                                    next(null)
                            ], callback

                    .test(email.toUpperCase())
                        next(new Error("Invalid email ID"))
                else
                    user = new User(email)
                    # Find if the user already exists in the admin interface collection
                    mongoInterface.findUser(user, 'admin_interface.users', next)
            (userRec, next) ->
                # Bypassing the waterfall
                if userRec then callback(null, user)
                else Read({prompt : "Password: ", silent : true}, next)
            (password, isDefault, next) ->
                hashPassword({password:password}, next)
            (result, next) ->
                # Insert into admin_interface collection
                user.key  = result.key.toString('hex')
                user.salt = result.salt.toString('hex')
                mongoInterface.addUser user, 'admin_interface.users',
                    (err, userRec) -> next(null, user)
        ], callback

    @run : () ->
