diff --git a/app/Console/Commands/CreateUser.php b/app/Console/Commands/CreateUser.php new file mode 100644 index 0000000..4cbd007 --- /dev/null +++ b/app/Console/Commands/CreateUser.php @@ -0,0 +1,141 @@ +info('Welcome to the user account creation wizard. If you just installed the application, we recommend you create your first admin user here. If you don\'t, you won\'t gain admin privileges after creating an account in the web interface.'); + $this->info('We\'ll ask some questions to get you started.'); + + $username = $this->ask('Username'); + do + { + $password = $this->secret('Password'); + $password_confirm = $this->secret('Confirm Password'); + + if ($password === $password_confirm) + { + $password = Hash::make($password); + $matches = true; + } + else + { + $this->error('Password doesn\'t match. Please try again.'); + $matches = false; + } + } + while(!$matches); + + $email = $this->ask('E-mail address'); + $name = $this->ask('First/Last Name'); + + do + { + try + { + $uuid = UUID::toUUID($this->ask('Minecraft username (Must be a valid Premium account)')); + } + catch (\InvalidArgumentException $e) + { + $this->error($e->getMessage()); + $hasError = true; + } + + if (isset($hasError)) + { + $continue = true; + } + else + { + $continue = false; + } + unset($hasError); + } + while($continue); + + + $this->info('Please check if these details are correct: '); + $this->info('Username: ' . $username); + $this->info('Email: ' . $email); + $this->info('Name: ' . $name); + + } + while(!$this->confirm('Create user now? You can go back to correct any details.')); + + + $user = User::create([ + 'uuid' => $uuid, + 'name' => $name, + 'email' => $email, + 'username' => $username, + 'originalIP' => '127.0.0.1', + 'password' => $password + ]); + + if ($user) + { + $user->assignRole('admin', 'reviewer', 'user', 'hiringManager'); + Profile::create([ + 'profileShortBio' => 'Random data '.rand(0, 1000), + 'profileAboutMe' => 'Random data '.rand(0, 1000), + 'socialLinks' => '[]', + 'avatarPreference' => 'gravatar', + 'userID' => $user->id, + ]); + + $this->info('Account created! You may now login at ' . route('login') . '. Enjoy the app!'); + + return 0; + } + else + { + $this->error('There was an unknown problem creating the user. There might have been errors above. Please try again.'); + return 1; + } + } +}