Skip to content

Commit

Permalink
get admin username and password from ENV instead
Browse files Browse the repository at this point in the history
  • Loading branch information
davemenninger committed Nov 17, 2014
1 parent d4e10cd commit 70a06af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ This is a test app for trying new things in Mojolicious.
* ~~prevent register dupe username~~
* ~~prevent bots with captcha or something ( how to automate tests then? )~~
* ~~script to create default admin user~~
* get default admin user/pass from ENV instead of hardcoded
* ~~get default admin user/pass from ENV instead of hardcoded~~
* ~~make authentication more secure ( bcrypt )~~
* ~~more tests for authentication, registration~~
* ~~add authorization ( logged in user can see some things, but not others )~~
* tests for authorization
* catch-all route, switch routes to use over() conditions
* ~~user can create document objects into mongo~~
* roles: ~~admin~~, ~~guest~~, author, reader?
* scripts: setup new db,
* scripts: setup new db,
* more templates/routes: ~~home~~, ~~user~~, user/:username, "posts" ...
* bootstrap, bower
* Dockerfile; add mongodb setup? fixtures?
Expand Down
24 changes: 14 additions & 10 deletions script/create_default_admin_user.pl → script/create_admin_user.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ sub _salt {
my $mongo_uri = $ENV{'MONGOLAB_URI'};
my $mango = Mango->new($mongo_uri);

# change this to get from ENV instead?
my $username = "hermes";
my $password = "conrad";

# insert admin user
my $doc = $mango->db->collection('users')->find_one( { username => $username } );
if ( $doc ) {
print $username . " already exists!\n";
if( defined $ENV{LRRR_ADMIN_USERNAME} && defined $ENV{LRRR_ADMIN_PASSWORD} ){
my $username = $ENV{LRRR_ADMIN_USERNAME};
my $password = $ENV{LRRR_ADMIN_PASSWORD};

# insert admin user
my $doc = $mango->db->collection('users')->find_one( { username => $username } );
if ( $doc ) {
print $username . " already exists!\n";
} else {
my $oid = $mango->db->collection('users')->insert( { username => $username, password => bcrypt($password,$settings), role => 'admin' } );
print "inserted ".$username." with oid: " . $oid . "\n";
}
} else {
my $oid = $mango->db->collection('users')->insert( { username => $username, password => bcrypt($password,$settings), role => 'admin' } );
print "inserted ".$username." with oid: " . $oid . "\n";
print "the ENV variables LRRR_ADMIN_USERNAME and LRRR_ADMIN_PASSWORD need to be set for this command to create a new admin user.\n";
}


# list existing admin users
my $c = $mango->db->collection('users')->find( { role => 'admin' } );
print "existing admins:\n";
Expand Down

0 comments on commit 70a06af

Please sign in to comment.