From edce1dcf54d8038b428df8e05db1052fb181f546 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 1 Mar 2019 12:05:19 -0700 Subject: [PATCH] Add UserCreate command --- app/Console/Commands/UserCreate.php | 88 +++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/Console/Commands/UserCreate.php diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php new file mode 100644 index 00000000..0945aff1 --- /dev/null +++ b/app/Console/Commands/UserCreate.php @@ -0,0 +1,88 @@ +info('Creating a new user...'); + + $name = $this->ask('Name'); + + $username = $this->ask('Username'); + + if(User::whereUsername($username)->exists()) { + $this->error('Username already in use, please try again...'); + exit; + } + + $email = $this->ask('Email'); + + if(User::whereEmail($email)->exists()) { + $this->error('Email already in use, please try again...'); + exit; + } + + $password = $this->secret('Password'); + $confirm = $this->secret('Confirm Password'); + + if($password !== $confirm) { + $this->error('Password mismatch, please try again...'); + exit; + } + + $is_admin = $this->confirm('Make this user an admin?'); + $confirm_email = $this->confirm('Manually verify email address?'); + + if($this->confirm('Are you sure you want to create this user?') && + $username && + $name && + $email && + $password + ) { + $user = new User; + $user->username = $username; + $user->name = $name; + $user->email = $email; + $user->password = bcrypt($password); + $user->is_admin = $is_admin; + $user->email_verified_at = $confirm_email ? now() : null; + $user->save(); + + $this->info('Created new user!'); + } + } +}