FEATURE: change directory structure

This commit is contained in:
Michal Kváček
2016-10-17 00:07:21 +02:00
parent 87f1920373
commit 2ded2924a1
242 changed files with 742 additions and 1171 deletions
+27 -11
View File
@@ -2,11 +2,10 @@
namespace App\Console\Commands;
use App\Enumerations\UserRoles;
use App\CMS\Enumerations\UserRoles;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Symfony\Component\Console\Exception\InvalidArgumentException;
class NewUser extends Command
{
@@ -15,7 +14,7 @@ class NewUser extends Command
*
* @var string
*/
protected $signature = 'user:new {email} {password} {role}';
protected $signature = 'user:new {email}';
/**
* The console command description.
*
@@ -25,21 +24,38 @@ class NewUser extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$email = $this->argument('email');
$password = $this->argument('password');
$role = $this->argument('role');
// check if given role is valid
$roles = UserRoles::getSimple();
if (!in_array($role, $roles)) {
throw new InvalidArgumentException('Invalid role specified. valid roles are: ' . implode(', ', $roles));
// check if username is really email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->error($email . ' is not a valid e-mail!');
return;
}
// ask for password
do {
$password = $this->secret('Password');
$passwordAgain = $this->secret('Password again');
if ($password !== $passwordAgain) {
$this->error('Passwords does not match');
}
} while ($passwordAgain !== $password || strlen($password) === 0);
// ask for role
$roles = UserRoles::getSimple();
do {
$role = $this->ask('Role (default ' . User::ROLE_ADMIN . '): ', User::ROLE_ADMIN);
// check if given role is valid
if (!in_array($role, $roles)) {
$this->error('Invalid role specified. valid roles are: ' . implode(', ', $roles));
}
} while (!in_array($role, $roles));
// create new user
$user = new User();
$user->username = $user->email = $email;