/**
  * 变更角色 - 页面
  *
  * @return \Illuminate\View\View
  */
 public function role_get()
 {
     $account_info = $this->account_info();
     $account_info['page_title'] = '变更角色';
     $account_info['page_description'] = '';
     if (!isset($_GET['user_id']) || $_GET['user_id'] <= 0) {
         //            dump('无法获取用户信息');
         return redirect($this->pre_web_page_url());
     }
     $user = Sentinel::findById($_GET['user_id']);
     if (!$user) {
         //            dump('无法获取用户信息');
         return redirect($this->pre_web_page_url());
     }
     $role = $this->role_by_user($user);
     $roles = Role::get();
     foreach ($roles as $k => $kValue) {
         $roles[$k]['value'] = 0;
         if ($kValue['id'] == $role['id']) {
             $roles[$k]['value'] = 1;
         }
     }
     $account_info['user'] = $user;
     $account_info['roles'] = $roles;
     return view('role.role', $account_info);
 }
Esempio n. 2
0
 public function emailFormSucceeded(Form $form, $values)
 {
     $spravci = $this->role->findBy(array('role' => array(2, 3)));
     $spravciEmaily = array();
     foreach ($spravci as $spravce) {
         $spravciEmaily[] = $spravce->uzivatel->email;
     }
     $this->mailer->sendKontaktMail($values->email, $values->name, $values->message, array_unique($spravciEmaily));
     $this->flashMessage('Zpráva byla úspěšeně odeslána.');
     $this->log->l('kontakt.send');
     $this->redirect('Kontakt:');
 }
Esempio n. 3
0
 /**
  * Add action method
  *
  * @return void
  */
 public function add()
 {
     $roleId = $this->getRoleId();
     $username = '';
     $email = null;
     $role = new Model\Role();
     $role->getById($roleId);
     $this->console->write();
     $dupeUser = Table\Users::findBy(['username' => $username]);
     while ($username == '' || isset($dupeUser->id)) {
         if (isset($dupeUser->id)) {
             $this->console->write($this->console->colorize('That username already exists.', Console::BOLD_RED));
             $username = '';
         }
         if ($role->email_as_username) {
             while (!(new Email())->evaluate($username)) {
                 $username = $this->console->prompt('Enter Email: ');
             }
             $email = $username;
         } else {
             while ($username == '') {
                 $username = $this->console->prompt('Enter Username: '******'';
                 while (!(new Email())->evaluate($email)) {
                     $email = $this->console->prompt('Enter Email: ');
                 }
             }
         }
         $dupeUser = Table\Users::findBy(['username' => $username]);
     }
     $password = '';
     while ($password == '') {
         $password = $this->console->prompt('Enter Password: '******'';
     while (strtolower($active) != 'y' && strtolower($active) != 'n') {
         $active = $this->console->prompt('Active? (Y/N): ');
     }
     $verified = '';
     while (strtolower($verified) != 'y' && strtolower($verified) != 'n') {
         $verified = $this->console->prompt('Verified? (Y/N): ');
     }
     $fields = ['role_id' => $roleId, 'username' => $username, 'password1' => $password, 'email' => $email, 'active' => strtolower($active) == 'y' ? 1 : 0, 'verified' => strtolower($verified) == 'y' ? 1 : 0];
     $user = new Model\User();
     $user->save($fields, $this->application->config()['application_title']);
     $this->console->write();
     $this->console->write($this->console->colorize('User Added!', Console::BOLD_GREEN));
 }
 public function shouldLockIfNoPermission($permission, $redirectedPage = '/', $message = 'You do not have permission to do this!')
 {
     if (!$this->session->has('user')) {
         $this->flash->warning('You must be logged in!');
         $this->redirect('/members/login?breadcrumb=' . h($_SERVER['REQUEST_URI']));
         return true;
     }
     $roleService = new Role($this->db);
     if (!$roleService->isAllowed($this->session->get('user.username'), $permission)) {
         $this->flash->warning($message);
         $this->redirect($redirectedPage);
         return true;
     }
     return false;
 }
Esempio n. 5
0
 public function startup()
 {
     parent::startup();
     if ($this->getName() != 'Admin:Sign' && !$this->user->isLoggedIn()) {
         $this->redirect('Sign:default');
     }
     //nastavim prava
     foreach ($this->roles->getAll() as $role) {
         $this->acl->addRole($role['system_name']);
     }
     foreach ($this->resources->getAll() as $resource) {
         $this->acl->addResource($resource['system_name']);
     }
     foreach ($this->permissions->getAll() as $permission) {
         $this->acl->allow($permission->role->system_name, $permission->resource->system_name, $permission->privilege->system_name);
     }
     $this->acl->addRole('super_admin');
     $this->acl->allow('super_admin');
     //homepage a sign maji pristup vsichni
     $this->acl->addResource('homepage');
     $this->acl->allow(\App\AdminModule\Components\Authorizator::ALL, 'homepage');
     $this->acl->addResource('sign');
     $this->acl->allow(\App\AdminModule\Components\Authorizator::ALL, 'sign');
     //vychozi role
     $this->acl->addRole('guest');
     //kontrola prav
     if ($this->getName() != 'Admin:Image' && $this->getAction() != 'ordering' && $this->getAction() != 'orderingCategory' && $this->getAction() != 'deleteImage' && $this->getAction() != 'changePassword' && $this->getAction() != 'getCity' && $this->getAction() != 'download') {
         if (!$this->getUser()->isAllowed($this->getNameSimple(), $this->getAction())) {
             $this->flashMessage($this->translator->translate('admin.login.noAccess'), 'error');
             $this->redirect('Homepage:default');
         }
     }
     //projedu vsek moduly a pokusim se najit presentery
     $presenters = array();
     $vsekDir = dirname(__FILE__) . '/../../../';
     $ch = opendir($vsekDir);
     while (($file = readdir($ch)) !== false) {
         if (!in_array($file, array('.', '..'))) {
             if (file_exists($vsekDir . $file . '/src/setting.xml')) {
                 $xml = simplexml_load_file($vsekDir . $file . '/src/setting.xml');
                 if (isset($xml->presenter)) {
                     $this->menuModules[] = array('name' => (string) $xml->presenter->name, 'resource' => (string) $xml->presenter->resource);
                 }
             }
         }
     }
     closedir($ch);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Role::truncate();
     factory(Role::class)->create(['name' => 'admin', 'display_name' => 'Administrador', 'description' => 'Para contas administradoras do sistema.']);
     factory(Role::class)->create(['name' => 'user', 'display_name' => 'Usuário', 'description' => 'Usuários cadastrados no sistema.']);
     factory(Role::class, 0)->create();
 }
Esempio n. 7
0
 protected function createComponentGrid($name)
 {
     $grid = new \App\Grid\Grid($this, $name);
     $grid->setModel($this->model->getAll());
     $grid->addColumn(new Column('name', $this->translator->translate('admin.form.name')));
     $grid->addColumn(new Column('system_name', $this->translator->translate('admin.form.systemName')));
     $grid->addColumn(new Column('id', $this->translator->translate('admin.grid.id')));
     $grid->addMenu(new \App\Grid\Menu\Update('edit', $this->translator->translate('admin.form.edit')));
     $grid->addMenu(new \App\Grid\Menu\Menu('permission', $this->translator->translate('admin.role.setPermission')));
     $grid->addMenu(new \App\Grid\Menu\Delete('delete', $this->translator->translate('admin.grid.delete')));
     $grid->setOrder('name');
     return $grid;
 }
Esempio n. 8
0
 private function loadUserRoles()
 {
     $userrole_query = Database::query("SELECT id, role_id FROM UserRole WHERE user_id = ? ORDER BY role_id", [$this->id]);
     if (!empty($userrole_query) && !empty($userrole_query[0])) {
         if ($userrole_query[0]['role_id'] == Role::seller()) {
             $this->seller_role_id = (int) $userrole_query[0]['id'];
             if (!empty($userrole_query[1]) && $userrole_query[1]['role_id'] == Role::buyer()) {
                 $this->buyer_role_id = (int) $userrole_query[1]['id'];
             }
         } else {
             if ($userrole_query[0]['role_id'] == Role::buyer()) {
                 $this->buyer_role_id = (int) $userrole_query[0]['id'];
             }
         }
     }
 }
Esempio n. 9
0
 protected function createComponentFormNew($name)
 {
     $form = new Form($this, $name);
     if ($this->getUser()->isInRole('super_admin')) {
         $roles = $this->roles->order('name')->fetchPairs('id', 'name');
     } else {
         $roles = $this->roles->order('name')->where('NOT system_name', 'super_admin')->fetchPairs('id', 'name');
     }
     $form->addSelect('role_id', $this->translator->translate('admin.user.role'), $roles);
     $form->addText('name', $this->translator->translate('admin.user.name'))->addRule(Form::FILLED, $this->translator->translate('admin.form.isRequired'));
     $form->addText('surname', $this->translator->translate('admin.user.surname'))->addRule(Form::FILLED, $this->translator->translate('admin.form.isRequired'));
     $form->addText('email', $this->translator->translate('admin.form.email'))->addRule(Form::FILLED, $this->translator->translate('admin.form.isRequired'))->addRule(Form::EMAIL, $this->translator->translate('admin.form.mustBeValidEmail'));
     $form->addPassword('password', $this->translator->translate('admin.form.password'))->addRule(Form::FILLED, $this->translator->translate('admin.form.isRequired'));
     $form->addPassword('password1', $this->translator->translate('admin.form.passwordRepead'))->addRule(Form::FILLED, $this->translator->translate('admin.form.isRequired'))->addRule(Form::EQUAL, $this->translator->translate('admin.form.passwordMustBeSame'), $form['password']);
     $form->addSubmit('send', $this->translator->translate('admin.form.create'));
     $form->onSuccess[] = [$this, 'submitFormNew'];
     return $form;
 }
Esempio n. 10
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function login(Request $request)
 {
     $rules = array('email' => 'required|email', 'password' => 'required');
     $credentials = Input::all();
     $email = $credentials['email'];
     $password = $credentials['password'];
     if (Auth::validate(array('email' => $email, 'password' => $password)) && Auth::attempt(array('email' => $email, 'password' => $password), false)) {
         Session::flash('message', 'Login Successfully!!!');
         Session::flash('status', 'success');
         $check_user_has_role = DB::table('role_user')->where('user_id', '=', Auth::User()->id)->first();
         if ($check_user_has_role == null) {
             $role = Role::all();
             if (Auth::User()->role == 1) {
                 $user = User::where('id', '=', Auth::User()->id)->first();
                 $user->attachRole($role[0]);
                 // return Redirect('permissionCreate');
             } else {
                 if (Auth::User()->role == 2) {
                     $user = User::where('id', '=', Auth::User()->id)->first();
                     $user->attachRole($role[1]);
                     // return Redirect('permissionCreate');
                 } else {
                     if (Auth::User()->role == 3) {
                         $user = User::where('id', '=', Auth::User()->id)->first();
                         $user->attachRole($role[2]);
                         //  return Redirect('permissionCreate');
                     }
                 }
             }
         }
         if (Auth::user()->hasRole('customer')) {
             return Redirect::intended('/po');
         } else {
             return Redirect::intended('/part');
         }
     } else {
         $error = 'wrong email or password..';
         Session::flash('messagelogin', $error);
         Session::flash('alert-class', 'alert-danger');
         return redirect('/')->withInput($request->only('email', 'remember'));
     }
 }
Esempio n. 11
0
 public function osobaCreateFormSucceeded(Form $form, $values)
 {
     if (!$this->user->loggedIn) {
         $this->error('Pro tuto akci musí být uživatel přihlášen.');
     }
     if (!$this->user->isInRole('spravce')) {
         $this->error('Omlouváme se, ale tato funkce je pouze pro správce.');
     }
     $osoby = $this->parseOsoby($values->osoby);
     foreach ($osoby as &$osoba) {
         $heslo = Model\UserManager::genPassword(10);
         $osoba['heslo'] = sha1($heslo);
         $osoba['chceMaily'] = 1;
         $this->mailer->sendRegistrace($osoba['jmeno'], $heslo, $osoba['email']);
         $id = $this->uzivatel->insert($osoba);
         $this->role->insert(array('role' => 1, 'uzivatel_id' => $id));
     }
     $this->flashMessage('Uživatelé byli úspěšně zaregistrováni. Heslo jim bylo zasláno na uvedený email.', 'success');
     $this->log->l('uzivatel.masscreate', count($osoby));
     $this->redirect('Osoby:default');
 }
Esempio n. 12
0
 public function processSignup(Request $request, Session $session)
 {
     if ($session->userIsLoggedIn()) {
         return $this->redirectTo('/dashboard');
     }
     if (isset($request->post['email']) && isset($request->post['password']) && (isset($request->post['buyer_account']) || isset($request->post['seller_account'])) && ($request->post['buyer_account'] == 1 || $request->post['seller_account'] == 1)) {
         if (Database::checkExists($request->post['email'], 'email', 'User')) {
             return View::renderView('login', ['signup_errors' => 'Email already exists']);
         }
         Database::insert('INSERT INTO User (email,password) VALUES (?,?)', [$request->post['email'], password_hash($request->post['password'], PASSWORD_DEFAULT)]);
         $user_id = Database::lastID();
         if ($request->post['buyer_account'] == 1) {
             Database::insert('INSERT INTO UserRole (user_id, role_id) VALUES (?,?)', [$user_id, Role::buyer()]);
         }
         if ($request->post['seller_account'] == 1) {
             Database::insert('INSERT INTO UserRole (user_id, role_id) VALUES (?,?)', [$user_id, Role::seller()]);
         }
         $session->generateSession($user_id);
         return $this->redirectTo('/dashboard');
     }
     return View::renderView('login', ['signup_errors' => 'You must complete the signup form']);
 }
Esempio n. 13
0
 public function show()
 {
     $data['roles'] = Role::all()->toArray();
     return view('admin.permission.index', $data);
 }
Esempio n. 14
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     Role::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }
Esempio n. 15
0
 /**
  * Edit action method
  *
  * @return void
  */
 public function edit($id)
 {
     $user = new Model\User();
     $user->getById($id);
     if (!isset($user->id)) {
         $this->redirect('/users');
     }
     if ($this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $user->role_id, 'edit')) {
         $this->prepareView('users/edit.phtml');
         $this->view->title = 'Edit User';
         $this->view->username = $user->username;
         $role = new Model\Role();
         $roles = $role->getAll();
         $roleValues = [];
         foreach ($roles as $r) {
             $roleValues[$r->id] = $r->name;
         }
         $fields = $this->application->config()['forms']['App\\Form\\User'];
         $fields[1]['username']['attributes']['onkeyup'] = 'pop.changeTitle(this.value);';
         $fields[1]['password1']['required'] = false;
         $fields[1]['password2']['required'] = false;
         $fields[0]['clear_logins']['value'][1] = $user->total_logins . ' Login' . ($user->total_logins == 1 ? '' : 's');
         $fields[0]['role_id']['type'] = 'select';
         $fields[0]['role_id']['label'] = 'Role';
         $fields[0]['role_id']['value'] = $roleValues;
         $fields[0]['role_id']['marked'] = $user->role_id;
         $this->view->form = new Form\User($fields);
         $this->view->form->addFilter('strip_tags', null, 'textarea')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray());
         if ($this->request->isPost()) {
             $this->view->form->addFilter('strip_tags', null, 'textarea')->setFieldValues($this->request->getPost());
             if ($this->view->form->isValid()) {
                 $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
                 $user = new Model\User();
                 $user->update($this->view->form->getFields(), $this->application->config()['application_title'], $this->sess);
                 $this->view->id = $user->id;
                 $this->sess->setRequestValue('saved', true);
                 $this->redirect('/users/edit/' . $user->id);
             }
         }
         $this->send();
     } else {
         $this->redirect('/users');
     }
 }
 public function view($id)
 {
     $message = 'You are not allowed to view this account!';
     if (!$this->session->get('user.id') === $id) {
         $this->shouldLockIfNoPermission('members.view', '/members', $message);
     }
     $accountService = new Account($this->db);
     $item = $accountService->findById($id);
     if ($item !== false) {
         $roleService = new Role($this->db);
         $roles = $roleService->getRolesOfAccount($item['username']);
         $allRoles = $roleService->getAllRoles();
         if ($roles !== false && $allRoles !== false) {
             $this->set('item', $item);
             $this->set('roles', $roles);
             $this->set('allRoles', $allRoles);
         } else {
             $this->flash->error('Unable to find member!');
             $this->redirect('/members');
         }
     } else {
         $this->flash->error('Unable to find member!');
         $this->redirect('/members');
     }
 }
Esempio n. 17
0
 /**
  * Remove action method
  *
  * @return void
  */
 public function remove()
 {
     $roleId = $this->getRoleId();
     $role = new Model\Role();
     $role->remove(['rm_roles' => [$roleId]]);
     $this->console->write();
     $this->console->write($this->console->colorize('Role Removed!', Console::BOLD_RED));
 }
Esempio n. 18
0
 /**
  * Remove action method
  *
  * @return void
  */
 public function remove()
 {
     if ($this->request->isPost()) {
         $role = new Model\Role();
         $role->remove($this->request->getPost());
     }
     $this->sess->setRequestValue('removed', true);
     $this->redirect('/roles');
 }
 /**
  * 新增帐户 - 页面
  *
  * @return \Illuminate\View\View
  */
 public function add_get()
 {
     $account_info = $this->account_info();
     $account_info['page_title'] = '新增账户';
     $account_info['page_description'] = '';
     $account_info['roles'] = Role::get();
     return view('account.add', $account_info);
 }
Esempio n. 20
0
 public function index(Request $request)
 {
     if ($request->input('username')) {
         return redirect('users/' . $request->input('username'));
     }
     $this->view->title = 'Users';
     $this->view->breadcrumbs = ['users' => 'Users'];
     $this->view->email_queue_count = \App\Model\QueuedEmail::count();
     $this->view->roles = Role::orderBy('name', 'ASC')->get();
     $this->view->users = User::orderBy('name', 'ASC')->paginate(20);
     $start = new \DateTime('today');
     $end = new \DateTime('1 month');
     $this->view->dates = new \DatePeriod($start, new \DateInterval('P1D'), $end);
     $this->view->day_count = iterator_count($this->view->dates);
     return $this->view;
 }
Esempio n. 21
0
 protected function users()
 {
     if (!Schema::hasTable('users')) {
         $this->info("Creating 'users' table.");
         Schema::create('users', function (Blueprint $table) {
             $table->increments('id');
             $table->string('name')->nullable();
             $table->string('username')->unique();
             $table->string('email')->nullable();
             $table->string('password', 60);
             $table->string('password_reminder', 100)->nullable();
             $table->rememberToken();
             $table->timestamps();
         });
     }
     if (User::count() == 0) {
         $this->info("No users found; creating 'admin'.");
         $adminUser = new User();
         $adminUser->username = '******';
         $adminUser->name = 'Administrator';
         $adminUser->password = bcrypt('admin');
         $adminUser->email = config('app.site_email');
         $adminUser->save();
     }
     if (!Schema::hasTable('roles')) {
         $this->info("Creating 'roles' table.");
         Schema::create('roles', function (Blueprint $table) {
             $table->increments('id');
             $table->string('name')->unique();
             $table->timestamps();
         });
     }
     if (!Role::find(Role::ADMIN)) {
         $this->info("Creating admin role.");
         Role::firstOrCreate(['id' => Role::ADMIN, 'name' => trans_choice('roles.admin', 1)]);
     }
     $managerRole = Role::find(Role::MANAGER);
     if (!$managerRole) {
         $this->info("Creating manager role.");
         Role::firstOrCreate(['id' => Role::MANAGER, 'name' => trans_choice('roles.manager', 1)]);
     }
     $clerkRole = Role::find(Role::CLERK);
     if (!$clerkRole) {
         $this->info("Creating clerk role.");
         Role::firstOrCreate(['id' => Role::CLERK, 'name' => trans_choice('roles.clerk', 1)]);
     }
     if (!Schema::hasTable('role_user')) {
         $this->info("Creating 'role_user' table.");
         Schema::create('role_user', function (Blueprint $table) {
             $table->integer('user_id')->unsigned();
             $table->foreign('user_id')->references('id')->on('users');
             $table->integer('role_id')->unsigned();
             $table->foreign('role_id')->references('id')->on('roles');
             $table->primary(['user_id', 'role_id']);
         });
     }
     // If there are no administrators, make the first user an admin.
     $adminRole = Role::find(Role::ADMIN);
     if (count(User::administrators()) === 0) {
         $adminUser = User::first();
         $this->info("Making " . $adminUser->name . " an Administrator.");
         $adminUser->roles()->save($adminRole);
     }
     if (!Schema::hasTable('unavailability_types')) {
         $this->info("Creating 'unavailability_types' table.");
         Schema::create('unavailability_types', function (Blueprint $table) {
             $table->increments('id');
             $table->string('name')->unique();
             $table->string('background_colour');
             $table->string('colour');
         });
     }
     if (!Schema::hasTable('user_unavailabilities')) {
         $this->info("Creating 'user_unavailabilities' table.");
         Schema::create('user_unavailabilities', function (Blueprint $table) {
             $table->increments('id');
             $table->integer('user_id')->unsigned()->nullable();
             $table->foreign('user_id')->references('id')->on('users');
             $table->date('start_date')->nullable();
             $table->date('end_date')->nullable();
             $table->integer('type_id')->unsigned()->nullable();
             $table->foreign('type_id')->references('id')->on('unavailability_types');
             $table->timestamps();
         });
     }
     if (!Schema::hasTable('queued_emails')) {
         $this->info("Creating 'queued_emails' table.");
         Schema::create('queued_emails', function (Blueprint $table) {
             $table->increments('id');
             $table->integer('recipient_id')->unsigned()->nullable();
             $table->foreign('recipient_id')->references('id')->on('users');
             $table->string('subject');
             $table->string('template');
             $table->text('data');
             $table->timestamps();
         });
     }
 }