/** * Run the database seeds. * * @return void */ public function run() { User::truncate(); \DB::table('user_meta')->truncate(); \DB::table('role_user')->truncate(); $roles = Role::pluck('id')->all(); $maxRolesToAttach = count($roles) > 4 ? 4 : count($roles); $faker = \Faker\Factory::create(); $totalUsers = 5; $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin', 'locale' => 'ru']); $user->roles()->sync($roles); $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin_en', 'locale' => 'en']); $user->roles()->sync([1, 2, 3]); $usedEmails = $usedUsernames = []; for ($i = 0; $i < $totalUsers; $i++) { do { $email = strtolower($faker->email); } while (in_array($email, $usedEmails)); $usedEmails[] = $email; do { $username = strtolower($faker->userName); } while (in_array($username, $usedUsernames)); $usedUsernames[] = $username; $user = User::create(['email' => $email, 'password' => 'password', 'name' => $username, 'locale' => $faker->randomElement(['ru', 'en'])]); $user->roles()->attach($faker->randomElements($roles, rand(1, $maxRolesToAttach))); } }
/** * @param string $filename */ public function getEdit($filename) { $file = $this->getFile($filename); $roles = Role::pluck('name', 'name')->all(); $this->setTitle(trans($this->wrapNamespace("{$this->sectionPrefix}.title.edit"), ['name' => $file->getName()])); $this->templateScripts['FILE'] = $file->toArray(); $this->setContent("{$this->sectionPrefix}.edit", compact('file', 'roles')); }
/** * Handle the event. * * @param UserRolesChanged $event * * @return void */ public function handle(UserRolesChanged $event) { if (count($event->getAttached()) > 0 or count($event->getDetached()) > 0) { $attached = Role::whereIn('id', $event->getAttached())->pluck('name')->implode(', '); $detached = Role::whereIn('id', $event->getDetached())->pluck('name')->implode(', '); $this->notifications->create($event->getUser(), ['icon' => 'comment outline', 'body' => trans('users::core.messages.user.roles_changed', ['attached' => $attached, 'detached' => $detached]), 'from' => auth()->user()]); } }
/** * Run the database seeds. * * @return void */ public function run() { Role::truncate(); Permission::truncate(); \DB::table('permission_role')->truncate(); $roles = [['name' => 'login', 'label' => 'Login privileges, granted after account confirmation.'], ['name' => 'administrator', 'label' => 'Administrative user, has access to everything.'], ['name' => 'developer', 'label' => '']]; foreach ($roles as $data) { Role::create($data); } }
/** * @param DispatcherContract $events */ public function boot(DispatcherContract $events) { $events->listen(UserRolesChanged::class, UserRolesChangedNotification::class); User::observe(new UserObserver()); Role::observe(new RoleObserver()); Event::listen('view.navbar.right.after', function () { echo view('users::parts.navbar')->render(); }); Event::listen('view.menu', function ($navigation) { echo view('users::parts.navigation')->render(); }, 999); $this->registerPermissions(); }
public function getAll() { $this->setContent(Role::get()); }
/** * @param \KodiCMS\Users\Model\Role $role * * @return bool */ public function deleted($role) { $role->users()->detach(); $role->permissions()->delete(); }
/** * Register any other events for your application. * * @param DispatcherContract $events * * @return void */ public function boot(DispatcherContract $events) { $events->listen('KodiCMS\\Pages\\Events\\FrontPageFound', function ($event) { $this->app->singleton('layout.widgets', function ($app) use($event) { return new PageWidgetCollection($app['widget.manager'], $event->getPage()->getId()); }); $block = new Block(app('layout.widgets')); $this->app->singleton('layout.block', function ($app) use($block) { return $block; }); }, 9000); $events->listen('view.page.create', function ($page) { echo view('widgets::widgets.page.create')->with('page', $page)->with('pages', $page->getSitemap())->render(); }); $events->listen('view.page.edit', function ($page) { if (acl_check('widgets::list') and $page->hasLayout()) { // echo view('widgets::widgets.page.iframe', compact('page'))->render(); echo view('widgets::widgets.page.list', ['page' => $page, 'widgetsCollection' => (new PageWidgetCollection(app('widget.manager'), $page->id))->getRegisteredWidgets()])->render(); } }); $events->listen('view.widget.edit', function ($widget) { if ($widget->isRenderable()) { $commentKeys = app('widget.manager')->getTemplateKeysByType($widget->type); $snippets = (new SnippetCollection())->getHTMLSelectChoices(); echo view('widgets::widgets.partials.renderable', compact('widget', 'commentKeys', 'snippets'))->render(); } if ($widget->isCacheable() and acl_check('widget_settings::cache')) { echo view('widgets::widgets.partials.cacheable', compact('widget'))->render(); } }); $events->listen('view.widget.edit.footer', function ($widget) { if ($widget->isRenderable()) { $assetsPackages = PackageManager::getHTMLSelectChoice(); $widgetList = Widget::where('id', '!=', $widget->id)->lists('name', 'id')->all(); echo view('widgets::widgets.partials.renderable_buttons', compact('widget', 'commentKeys', 'snippets', 'assetsPackages', 'widgetList'))->render(); } if (acl_check('widget_settings::roles') and !$widget->isHandler()) { $usersRoles = Role::pluck('name', 'id')->all(); echo view('widgets::widgets.partials.permissions', compact('widget', 'usersRoles'))->render(); } }); $events->listen('view.widget.edit.settings', function ($widget) { if ($widget->toWidget() instanceof WidgetPaginator) { echo view('widgets::widgets.paginator.widget', ['widget' => $widget->toWidget()])->render(); } }); $events->listen('view.widget.edit.footer', function ($widget) { if ($widget->isHandler()) { echo view('widgets::widgets.partials.handler', compact('widget'))->render(); } }); Page::created(function ($page) { $pageId = array_get(Request::get('widgets'), 'from_page_id'); if (!empty($pageId)) { app('widget.manager')->copyWidgets($pageId, $page->id); } }); Page::deleted(function ($page) { app('widget.manager')->deleteWidgetsFromPage($page->id); }); Page::saving(function ($page) { $postData = Request::input('widget', []); foreach ($postData as $widgetId => $location) { if (array_key_exists('block', $location)) { app('widget.manager')->updateWidgetOnPage($widgetId, $page->id, $location); } } }); Widget::observe(new WidgetObserver()); }
/** * Assign the given role to the user. * * @param string $role * * @return mixed */ public function assignRole($role) { return $this->roles()->save(Role::whereName($role)->firstOrFail()); }