Example #1
0
 protected static function createAdminUser()
 {
     echo "Create New Admin User: \n";
     do {
         $passwordSalt = Helper::get()->input("Password Salt(min 6 chars - used to encrypt passwords)", uniqid("D#A") . "D#\$D");
     } while (strlen($passwordSalt) < 6);
     File::searchAndReplace(dirname(self::$APP_CONFIG_DIR) . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'User.php', "'342!\$!@D#ASDA3d44'", "'{$passwordSalt}'");
     $name = Helper::get()->input("Name");
     $email = Helper::get()->input("Email");
     $password = Helper::get()->passwordInput("Password");
     $userId = SQL::$connection->table('users')->insert(['name' => $name, 'email' => $email, 'status' => \app\models\User::STATUS_ACTIVE, 'password' => \app\models\User::hashPassword($password)], 'ignore');
     // don't create if an user is already there
     $groups = SQl::$connection->table('users_groups')->get();
     $table = SQL::$connection->table('users2groups');
     foreach ($groups as $group) {
         // add all possible groups to this user.
         $table->insert(['group_id' => $group['id'], 'user_id' => $userId], 'IGNORE');
     }
     echo "\n" . Helper::get()->color("DONE!", Helper::CLIGHT_GREEN) . "\n";
 }