/** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = (require __DIR__ . '/../bootstrap/app.php'); $app->make('Illuminate\\Contracts\\Console\\Kernel')->bootstrap(); $this->user = User::find($this->userId); return $app; }
/** * {@inheritdoc}. */ protected function getModelFromRequest() { $netblock = new Netblock(); $netblock->contact()->associate(User::find($this->argument('contact'))); $netblock->first_ip = $this->argument('first_ip'); $netblock->last_ip = $this->argument('last_ip'); $netblock->description = $this->argument('description'); $netblock->enabled = $this->argument('enabled') === 'true' ? true : false; return $netblock; }
/** * {@inheritdoc}. */ protected function getObjectByArguments() { $user = false; if (!is_object($user)) { $user = User::where('email', $this->argument('user'))->first(); } if (!is_object($user)) { $user = User::find($this->argument('user')); } return $user; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('user'))) { $this->warn('no email or id argument was passed, try --help'); return false; } $user = false; if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = User::find($this->option('user')); } if (!is_object($user)) { $this->error('Unable to find user with this criteria'); return false; } $roleList = []; $roles = $user->roles()->get(); foreach ($roles as $role) { if (is_object($role)) { $roleList[] = $role->description; } } $account = $user->account()->first(); if (!is_object($account)) { $account = 'None'; } else { $account = $account->name; } $table = []; $counter = 0; foreach (array_combine($this->headers, $this->fields) as $header => $field) { $counter++; $table[$counter][] = $header; if ($header == 'Disabled') { $table[$counter][] = (bool) $user->{$field} ? 'YES' : 'NO'; } elseif ($header == 'Account') { $table[$counter][] = $account; } elseif ($header == 'Roles') { $table[$counter][] = implode(', ', $roleList); } else { $table[$counter][] = (string) $user->{$field}; } } $userlist[] = $user; $this->table(['User Setting', 'User Value'], $table); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('id'))) { $this->warn('The required id argument was not passed, try --help'); return false; } /** @var Netblock|null $netblock */ $netblock = Netblock::find($this->option('id')); if (null === $netblock) { $this->error('Unable to find netblock with this criteria'); return false; } if (!empty($this->option("contact"))) { /** @var User|null $user */ $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first(); if (null === $user) { $this->error("Unable to find contact with this criteria"); return false; } $netblock->contact()->associate($user); } $stringOptions = ["first_ip", "last_ip", "description"]; foreach ($stringOptions as $option) { if (!empty($this->option($option))) { $netblock->{$option} = $this->option($option); } } if (!empty($this->option("enabled"))) { $netblock->enabled = castStringToBool($this->option("enabled")); } $validation = Validator::make($netblock->toArray(), Netblock::updateRules($netblock)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the netblock due to validation warnings'); return false; } $netblock->save(); $this->info("Netblock has been successfully updated"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('id'))) { $this->warn('The required id argument was not passed, try --help'); return false; } /** @var Domain|null $domain */ $domain = Domain::find($this->option('id')); if (null === $domain) { $this->error('Unable to find domain with this criteria'); return false; } if (!empty($this->option("contact"))) { /** @var User|null $user */ $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first(); if (null === $user) { $this->error("Unable to find contact with this criteria"); return false; } $domain->contact()->associate($user); } if (!empty($this->option("name"))) { $domain->name = $this->option("name"); } if (!empty($this->option("enabled"))) { $domain->enabled = castStringToBool($this->option("enabled")); } $validation = Validator::make($domain->toArray(), Domain::updateRules($domain)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the domain due to validation warnings'); return false; } $domain->save(); $this->info("Domain has been successfully updated"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('user'))) { $this->warn('the required user argument was not passed, try --help'); return false; } $user = false; if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = User::find($this->option('user')); } if (!is_object($user)) { $this->error('Unable to find user with this criteria'); return false; } // Apply changes to the user object if (!empty($this->option('email'))) { $user->email = $this->option('email'); } if (!empty($this->option('password'))) { $user->password = $this->option('password'); } if (!empty($this->option('autopassword'))) { $generatedPassword = substr(md5(rand()), 0, 8); $this->info("Using auto generated password: {$generatedPassword}"); $user->password = $generatedPassword; } if (!empty($this->option('firstname'))) { $user->first_name = $this->option('firstname'); } if (!empty($this->option('lastname'))) { $user->last_name = $this->option('lastname'); } if (!empty($this->option('account'))) { $account = Account::where('name', '=', $this->option('account'))->first(); if (!is_object($account)) { $this->error("The account named {$this->option('account')} was not found"); return false; } $user->account_id = $account->id; } if (!empty($this->option('language'))) { $user->locale = $this->option('language'); } if (!empty($this->option('disable'))) { $user->disabled = true; } if (!empty($this->option('enable'))) { $user->disabled = false; } // Validate the changes $validation = Validator::make($user->toArray(), User::updateRules($user)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the user due to validation warnings'); return false; } // Save the object $user->save(); $this->info("User has been successfully updated"); return true; }
protected function findUserWithOutput($output) { return User::find($this->returnIdFromSuccessOutput($output)); }
/** * @return User|null */ private function findUserByIdOrEmail($param) { $contact = User::find($param) ?: User::where('email', '=', $param)->first(); return $contact; }