Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $create = $this->option('create');
     $delete = $this->option('delete');
     if (!empty($create)) {
         $name = $this->ask('Enter the name of the user:'******'Enter the name of the user:'******'Enter the password for the user:'******'Make sure the password is longer than 5 characters');
             $password = $this->secret('Enter the password for the user:'******'Re-enter the password to confirm:');
         while ($pwConfirm != $password) {
             $pwConfirm = $this->secret('The passwords did not match, re-enter the password to confirm:');
         }
         // Create 'everyone' user and group
         Sentry::getUserProvider()->create(array('email' => $name, 'password' => $pwConfirm, 'first_name' => $name, 'last_name' => '', 'activated' => 1));
         $newUser = Sentry::getUserProvider()->findByLogin($name);
         $adminGroup = Sentry::getGroupProvider()->findByName('superadmin');
         $newUser->addGroup($adminGroup);
         $this->info('The user ' . $name . ' has been created and activated.');
     } else {
         if (!empty($delete)) {
             $name = $this->ask('Enter the name of the user you want to delete.');
             while (empty($name)) {
                 $name = $this->ask('Enter the name of the user you want to delete.');
             }
             $user = User::where(['email' => $name])->first();
             if (empty($user)) {
                 $this->error('No user with the name ' . $name . ' has been found.');
             } else {
                 if ($this->confirm('The user ' . $name . ' has been found, are you sure you want do delete? [yes|no]')) {
                     $user->delete();
                 } else {
                     $this->info('The user ' . $name . ' has not been removed.');
                 }
             }
         } else {
             // Get all of the users
             $users = User::all(['email'])->toArray();
             foreach ($users as $user) {
                 if ($user['email'] != 'everyone') {
                     $this->info($user['email']);
                 }
             }
         }
     }
 }