/**
  * @param $faker
  */
 private function seedTable($faker)
 {
     foreach (range(1, 25) as $index) {
         User::create(['name' => $faker->name, 'email' => $faker->email, 'username' => $faker->word . $index, 'password' => '123456']);
     }
     User::create(['name' => 'Site Admin', 'email' => '*****@*****.**', 'username' => 'superadmin', 'password' => '123456', 'superadmin' => 1]);
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::where('email', $command->email)->firstOrFail();
     User::updatePassword($user->id, $command->password);
     User::login($user->username, $command->password);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Return a single user model based on the given user id
  *
  * @param $userId
  * @param array $with
  * @param bool $withTrashed
  *
  * @return null
  */
 public function getUser($userId, $with = [], $withTrashed = false)
 {
     if (!$userId) {
         return null;
     }
     $query = User::with($with);
     return $withTrashed ? $query->withTrashed()->find($userId) : $query->find($userId);
 }
 /**
  * handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     Input::merge(['roleIds' => []]);
     $this->execute(UpdateUserRolesCommand::class);
     $user = User::deleteUser($command->userId);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::updateProfile($command->userId, $command->email, $command->username, $command->name);
     if (!is_null($command->roleIds)) {
         $this->execute(UpdateUserRolesCommand::class);
     }
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::register($command->email, $command->name, $command->username, $command->password, $command->anonymousUser);
     \Input::merge(['userId' => $user->id]);
     // assign selected roles to the newly registered user
     $this->execute(UpdateUserRolesCommand::class);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * @param $command
  *
  * @return bool
  * @throws UnauthorizedUserActionException
  */
 public function authorizeCommand($command)
 {
     $user = Auth::check() ? Auth::user() : User::whereUsername($command->username)->first();
     if (!$user || $user->superadmin) {
         return true;
     }
     $userCapabilities = $user->capabilities()->lists('name');
     if ($this->isUnauthorized($userCapabilities) || !$this->isAuthorized($userCapabilities)) {
         throw new UnauthorizedUserActionException('You are not authorized to do this action');
     }
     return true;
 }
 private function tableSeed()
 {
     $allUsers = User::all();
     $adminUsers = User::where('username', 'LIKE', '%2%')->get();
     $staffUsers = User::where('username', 'NOT LIKE', '%2%')->get();
     foreach ($adminUsers as $user) {
         $user->roles()->sync([Role::whereName('admin')->first()->id]);
     }
     foreach ($staffUsers as $user) {
         $user->roles()->sync([Role::whereName('staff')->first()->id]);
     }
     foreach ($allUsers as $user) {
         $user->roles()->attach(Role::whereName('user')->first()->id);
     }
 }
 /**
  * handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $user = User::restoreUser($command->userId);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::updatePassword($command->userId, $command->password);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::login($command->username, $command->password);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::updateRoles($command->userId, $command->roleIds);
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return User
  */
 public function Handle($command)
 {
     $user = User::logout();
     $this->dispatchEventsFor($user);
     return $user;
 }