示例#1
0
 public function handle($request, Closure $next)
 {
     if (!Auth::check()) {
         return LoginController::getIndex();
     }
     return $next($request);
 }
示例#2
0
 public function savePermissions($table)
 {
     DB::table(config('center.db.permissions'))->where('table', $table)->delete();
     foreach (Request::input('permissions') as $user => $level) {
         if (!empty($level)) {
             DB::table(config('center.db.permissions'))->insert(['table' => $table, 'user_id' => $user, 'level' => $level]);
         }
     }
     LoginController::updateUserPermissions();
     return redirect(action('\\LeftRight\\Center\\Controllers\\RowController@index', $table))->with('message', trans('center::site.permissions_update_success'));
 }
示例#3
0
 public function handle($request, Closure $next)
 {
     if (Auth::check()) {
         if (!Session::has('center.permissions')) {
             LoginController::updateUserPermissions();
         }
     } else {
         if (Session::has('center.permissions')) {
             Session::forget('center.permissions');
         }
     }
     return $next($request);
 }
示例#4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $tables = config('center.tables');
     $joining_tables = [];
     //dd($tables);
     foreach ($tables as $table) {
         //create if doesn't exist, every table gets an id
         if (!Schema::hasTable($table->name)) {
             Schema::create($table->name, function ($t) {
                 $t->increments('id');
             });
         }
         foreach ($table->fields as $field) {
             if ($field->type == 'checkboxes') {
                 //create linking table
                 if (!Schema::hasTable($field->name)) {
                     Schema::create($field->name, function ($t) {
                         $t->increments('id');
                     });
                 }
                 $column = RowController::formatKeyColumn($table->name);
                 if (!Schema::hasColumn($field->name, $column)) {
                     Schema::table($field->name, function ($t) use($column) {
                         $t->integer($column);
                     });
                 }
                 $column = RowController::formatKeyColumn($field->source);
                 if (!Schema::hasColumn($field->name, $column)) {
                     Schema::table($field->name, function ($t) use($column) {
                         $t->integer($column);
                     });
                 }
             } else {
                 //create column
                 Schema::table($table->name, function ($t) use($table, $field) {
                     //set type
                     switch ($field->type) {
                         //boolean
                         case 'checkbox':
                             eval('$t->boolean($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //strings
                         //strings
                         case 'address':
                         case 'color':
                         case 'country':
                         case 'email':
                         case 'password':
                         case 'phone':
                         case 'slug':
                         case 'stripe_charge':
                         case 'stripe_customer':
                         case 'string':
                         case 'url':
                         case 'us_state':
                         case 'zip':
                             if (!isset($field->maxlength)) {
                                 $field->maxlength = 255;
                             }
                             eval('$t->string($field->name, $field->maxlength)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //date
                         //date
                         case 'date':
                             eval('$t->date($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //datetime
                         //datetime
                         case 'datetime':
                             eval('$t->datetime($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //time
                         //time
                         case 'time':
                             eval('$t->time($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //text
                         //text
                         case 'html':
                         case 'text':
                             eval('$t->text($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //foreign key
                         //foreign key
                         case 'image':
                         case 'integer':
                         case 'select':
                         case 'user':
                             eval('$t->integer($field->name)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //decimal
                         //decimal
                         case 'money':
                             eval('$t->decimal($field->name, 5, 2)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //latitude
                         //latitude
                         case 'latitude':
                             eval('$t->decimal($field->name, 11, 8)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //latitude
                         //latitude
                         case 'longitude':
                             eval('$t->decimal($field->name, 11, 8)' . ($field->required ? '' : '->nullable()') . (!Schema::hasColumn($table->name, $field->name) ? '' : '->change()') . '; ');
                             break;
                             //special: permissions
                         //special: permissions
                         case 'permissions':
                             break;
                         default:
                             trigger_error($field->type . ' not supported yet!');
                     }
                     //remove unused columns?
                     if ($table->keep_clean) {
                         $columns = Schema::getColumnListing($table->name);
                         $fields = array_keys((array) $table->fields);
                         $columns = array_diff($columns, $fields, ['id']);
                         foreach ($columns as $column) {
                             $t->dropColumn($column);
                         }
                     }
                 });
             }
         }
     }
     //now can set permissions, had to wait for permissions table potentially to be created
     foreach ($tables as $table) {
         //set default permissions
         if (!$table->hidden) {
             LoginController::setDefaultTablePermissions($table->name);
         }
     }
     $this->comment(PHP_EOL . trans('center::site.refresh_success') . PHP_EOL);
 }
示例#5
0
 public static function pdf($table, $row_id)
 {
     # Get object / field / whatever infoz
     $table = config('center.tables.' . $table);
     # Security
     if (!isset($table->name)) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
     } elseif (!LoginController::checkPermission($table->name, 'view') || !$table->editable) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name)->with('error', trans('center::site.no_permissions_edit'));
     }
     # Retrieve instance/row values
     $row = DB::table($table->name)->where('id', $row_id)->first();
     # Output PDF to the browser
     return PDF::loadView('center::rows.pdf', compact('table', 'row'))->setPaper('letter', 'portrait')->stream($table->name . '-' . $row->id . '.pdf');
 }