/** * Handle a login request to the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required']); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. $throttles = $this->isUsingThrottlesLoginsTrait(); if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); } $credentials = $this->getCredentials($request); $user = User::where('email', '=', $credentials['email'])->first(); if ($user) { $messages = []; if (!$user->mayLogin($messages)) { return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $messages]); } } if (Auth::attempt($credentials, $request->has('remember'))) { return $this->handleUserWasAuthenticated($request, $throttles); } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. if ($throttles) { $this->incrementLoginAttempts($request); } return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]); }
/** * {@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('role')) && empty($this->option('user'))) { $this->error('Missing options for role and/or user(e-mail) to select'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; $user = false; if (!empty($this->option('role'))) { if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } } if (!empty($this->option('user'))) { if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = Role::find($this->option('user')); } } if (!is_object($role) || !is_object($user)) { $this->error('Unable to find role with this criteria'); return false; } $RoleUser = new RoleUser(); $RoleUser->user_id = $user->id; $RoleUser->role_id = $role->id; $validation = Validator::make($RoleUser->toArray(), RoleUser::createRules($RoleUser)); if ($validation->fails()) { $this->warn('The role has already been granted this permission'); $this->error('Failed to create the permission due to validation warnings'); return false; } if (!$RoleUser->save()) { $this->error('Failed to save the permission into the database'); return false; } $this->info("The role {$role->name} has been granted to user {$user->email}"); return true; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role')) && empty($this->option('user'))) { $this->error('Missing options for role and/or user(e-mail) to select'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; $user = false; if (!empty($this->option('role'))) { if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } } if (!empty($this->option('user'))) { if (!is_object($user)) { $user = User::where('email', $this->option('user'))->first(); } if (!is_object($user)) { $user = Role::find($this->option('user')); } } if (!is_object($role) || !is_object($user)) { $this->error('Unable to find role with this criteria'); return false; } $roleUser = RoleUser::all()->where('role_id', $role->id)->where('user_id', $user->id)->first(); if (!is_object($roleUser)) { $this->error('Nothing to delete, this {$permission->name} permission is not linked to the role {$role->name}'); return false; } if (!$roleUser->delete()) { $this->error('Failed to remove the permission into the database'); return false; } $this->info("The role {$role->name} has been revoked from role {$user->email}"); 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; }
/** * {@inheritdoc}. */ protected function getModelFromRequest() { return User::where('id', $this->argument('user'))->orWhere('email', $this->argument('user'))->first(); }
/** * 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; }
/** * {@inherit docs}. */ protected function getCollectionWithArguments() { return User::where('id', $this->argument('user')); }
/** * {@inheritdoc } */ protected function findWithCondition($filter) { $users = User::where('email', 'like', "%{$filter}%")->get($this->fields); return $this->hydrateWithRoles($users); }
/** * @return User|null */ private function findUserByIdOrEmail($param) { $contact = User::find($param) ?: User::where('email', '=', $param)->first(); return $contact; }