/** * Execute the console command. * * @return mixed */ public function handle() { $this->line('SeAT Admin Reset Tool'); $admin = User::firstOrNew(['name' => 'admin']); if (!$admin->exists) { $this->warn('User \'admin\' does not exist. It will be created.'); } $password = null; while (strlen($password) < 6) { $password = $this->secret('Please enter a min 6 character password for the \'admin\' user'); } $this->line('Setting password'); $admin->fill(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt($password)])->save(); $this->line('Checking if \'admin\' is a super user'); if (!$admin->has('superuser')) { $this->line('Searching for the \'Superuser\' role'); $role = Role::where('title', 'Superuser')->first(); if (!$role) { $this->comment('Creating the Superuser role'); $role = Role::create(['title' => 'Superuser']); } $this->line('Checking if the Superuser role has the superuser permission'); $role_permissions = $this->getCompleteRole($role->id)->permissions; if (!$role_permissions->contains('superuser')) { $this->comment('Adding the superuser permission to the role'); $this->giveRolePermission($role->id, 'superuser', false); } $this->comment('Adding \'admin\' to the Superuser role'); $this->giveUserRole($admin->id, $role->id); } $this->line('Ensuring the \'admin\' user is enabled.'); if (!$admin->active) { $admin->active = true; $admin->save(); } // Analytics $this->dispatch((new Analytics((new AnalyticsContainer())->set('type', 'event')->set('ec', 'admin')->set('ea', 'password_reset')->set('el', 'console')))->onQueue('medium')); $this->info('Done'); }
/** * Remove a role by title * * @param $title */ public function removeRoleByTitle($title) { $role = RoleModel::where('title', $title)->first(); $this->removeRole($role->id); return; }