From 3b29cb04a53a5a3167781b8c41d809492e12aa87 Mon Sep 17 00:00:00 2001
From: MGatner <mgatner@tattersoftware.com>
Date: Wed, 5 Feb 2020 11:58:33 -0500
Subject: [PATCH] Add required fields to CreateUser

---
 src/Commands/CreateUser.php | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/Commands/CreateUser.php b/src/Commands/CreateUser.php
index 37714487..91389b40 100644
--- a/src/Commands/CreateUser.php
+++ b/src/Commands/CreateUser.php
@@ -11,7 +11,7 @@ class CreateUser extends BaseCommand
     protected $group       = 'Auth';
     protected $name        = 'auth:create_user';
     protected $description = "Adds a new user to the database.";
-    
+
 	protected $usage     = "auth:create_user [username] [email]";
 	protected $arguments = [
 		'username'        => "The username of the new user to create",
@@ -20,15 +20,19 @@ class CreateUser extends BaseCommand
 
 	public function run(array $params = [])
     {
-    	$row = [];
-    	
+		// Start with the fields required for the account to be usable
+		$row = [
+			'active'   => 1,
+			'password' => bin2hex(random_bytes(24)),
+		];
+
 		// Consume or prompt for username
 		$row['username'] = array_shift($params);
 		if (empty($row['username']))
 		{
 			$row['username'] = CLI::prompt('Username', null, 'required');
 		}
-		
+
 		// Consume or prompt for email
 		$row['email'] = array_shift($params);
 		if (empty($row['email']))
@@ -36,10 +40,10 @@ public function run(array $params = [])
 			$row['email'] = CLI::prompt('Email', null, 'required');
 		}
 
-		// Save the user
-		$users = new UserModel();
+		// Run the user through the entity and save it
 		$user = new User($row);
 
+		$users = new UserModel();
 		if ($userId = $users->insert($user))
 		{
 			CLI::write(lang('Auth.registerCLI', [$row['username'], $userId]), 'green');