TZM / tzm-blade

ZMGC Application empowers members with on-line tools, by providing a free infrastructure to easily exchange, analyse and disseminate information in a scalable, non-blocking manner using only Open Source software build by the community for the community. It is about building lasting and deep solidarity versus cheap and fast Facebook or Twitter campaigns
www.zmgc.net
GNU General Public License v3.0
4 stars 8 forks source link

initial admin user #56

Closed nkhine closed 10 years ago

nkhine commented 10 years ago

We need the ability to create an initial admin user when we start the application with the following options:

--email --help --port

so that when we run

☺ cake dev --email your@email.tld

should first check if there is a user in the database with this email, if yes, then update the group for this user to 'admin' if not add the user to the database and generate a password.

so you get something like this in the console:

☺ cake dev --email your@email.tld
*
* Welcome to ZMGC
* A user with administration rights has been created for you:
*   username: your@email.tld
*   password: 'randomly_Generated'
*
* Server running at:
*    http://127.0.0.1:3000
*

this user should be verified and there is no need to send a verification token.

if you run:

☺ cake dev --help
Usage: cake dev -- [OPTIONS]

Creates a new instance of zmgc.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -e EMAIL, --email=EMAIL
                        e-mail address of the admin user
  -p PORT, --port=PORT  listen to PORT number

if you add the --port then the instance is started on that port number

ofShard commented 10 years ago

I should note that cake arguments are set before the task name, such as:

cake -e your@email.tld dev

Do you want that 'randomly_Generated' text to be replaced with the plaintext password? Perhaps we can set the password with cake dev as well. Something to this effect:

cake --admin your@email.tld --password my_password dev

ofShard commented 10 years ago

Or as a design change, we might have a cake task specifically for creating admin users.

cake admin             # create new administrator accounts

  -e, --email       the email address that serves as the login
  -p, --password    [optional] the password for that admin. If omitted, will be randomly generated.
nkhine commented 10 years ago

maybe cake setup will be better as we can then use it for other setup tasks

ofShard commented 10 years ago

So something like cake -e email@domain.tld -pw my_password setup?

nkhine commented 10 years ago

yes that should be ok

On Sat, Feb 15, 2014 at 7:18 PM, ofShard notifications@github.com wrote:

So something like cake -e email@domain.tld -pw my_password setup?

— Reply to this email directly or view it on GitHubhttps://github.com/TZM/tzm-blade/issues/56#issuecomment-35164944 .

%>>> "".join( [ {'':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) for c in ",adym,)&uzq^zqf" ] )

ofShard commented 10 years ago

I've changed the setup for the setup command. Instead of providing the email and password as arguments, they are prompted.

cake -aw setup will prompt for an email and password. cake -a setup will only prompt for an email. It will still prompt for password if the email doesn't exist.

nkhine commented 10 years ago

i got prompted for the password 2 times:

☺  cake -aw setup                                                        ruby-2.0.0-p195 mdm 3d592c6""
setup { arguments: [ 'setup' ], admin: true, password: true }
null
mongodb://localhost:27017/zmgc-mongo
prompt: email:  norman@zmgc.net
prompt: password:
Mongoose: users.ensureIndex({ email: 1 }) { safe: undefined, background: true, unique: true }
Mongoose: users.findOne({ email: 'norman@zmgc.net' }) { fields: undefined }
creating user
prompt: password:
Mongoose: users.findOne({ email: 'norman@zmgc.net' }) { fields: undefined }
Mongoose: users.insert({ __v: 0, password: '$2a$10$I/IjKyba9vaKd.jaqWaYseR63N4wmSb23jUbuj.EMTB20uvwIe5.W', active: true, name: 'user', surname: '', groups: 'admin', loginAttempts: 0, lockUntil: 0, provider: [], _id: ObjectId("53026204f11aa717b9569653"), email: 'norman@zmgc.net', awaitConfirm: true, tokenString: 'EpTqtFmnw-pvImf7WD-o1nELdH2DwjiNAiAMS5K6ZYaYf3AO01AZULWrA84jRaOV', tokenExpires: 1392751492850 }) {}
user norman@zmgc.net is admin: password set
nkhine commented 10 years ago

i get this, when running on heroku:

☺  heroku run cake --admin setup                                                  ruby-2.0.0-p195 master f036574""
Running `cake --admin setup` attached to terminal... up, run.5948
setup { arguments: [ 'setup' ], admin: true }

module.js:340
    throw err;
          ^
Error: Cannot find module './app/utils/dbconnect'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.process.env.EMAIL [as action] (/app/Cakefile:163:17)
  at helpers.extend.invoke (/app/node_modules/coffee-script/lib/coffee-script/cake.js:42:26)
  at Object.exports.run (/app/node_modules/coffee-script/lib/coffee-script/cake.js:68:21)
  at Object.<anonymous> (/app/node_modules/coffee-script/bin/cake:7:38)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:902:3
nkhine commented 10 years ago

This still is not working on heroku, as there is an issue with the finding the module, you can test this by accessing heroku through the terminal as:

☺ heroku run bash
Running `bash` attached to terminal... up, run.6563
~ $ cake --admin norman@x11.us --password P4SSWord setup

module.js:340
    throw err;
          ^
Error: Cannot find module './app/utils/dbconnect'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.process.env.EMAIL [as action] (/app/Cakefile:175:17)
  at helpers.extend.invoke (/app/node_modules/coffee-script/lib/coffee-script/cake.js:42:26)
  at Object.exports.run (/app/node_modules/coffee-script/lib/coffee-script/cake.js:68:21)
  at Object.<anonymous> (/app/node_modules/coffee-script/bin/cake:7:38)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:902:3

the issue maybe that heroku instances are all stored in a directory app if you look at the root you have this:

/ $ ls
app  bin  dev  etc  home  lib  lib64  lost+found  proc  sbin  tmp  usr  var
/ $ ls app
BENCHMARK.md  Cakefile     Makefile  README.md  assets  layout   middlewere    npm-shrinkwrap.json  public  test    uploads  views
CHANGELOG.md  LICENSE.txt  Procfile  app    data    locales  node_modules  package.json     run.js  upgrade.sh  vendor

i can run the application from the command prompt:

~ $ cake dev
dev options { arguments: [ 'dev' ] }
Watching coffee files
Watching js files and running server

DEBUG: Running node-supervisor with
DEBUG:   program 'run'
DEBUG:   --watch 'app,views'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'js|blade'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node run'
DEBUG: Watching directory '/app/app' for changes.
DEBUG: Watching directory '/app/views' for changes.
null
created uploads folder
NOW USING CPU: # 0
NOW USING CPU: # 1
NOW USING CPU: # 2
NOW USING CPU: # 3
null
null
null
null
info: [APP config] --- App server created and local env set to: production undefined undefined
info: [APP config] --- Server running on port: 17653 undefined undefined
...