Working on multi user
This commit is contained in:
parent
e8b47776ce
commit
46bb073001
27 changed files with 184 additions and 38 deletions
|
@ -36,4 +36,9 @@ class LoginController extends Controller
|
|||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$data =[];
|
||||
return view('userselect', $data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,26 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
|
|||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
protected $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->user = $this->user();
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
if (Auth::check()) { // if logged in, set this user
|
||||
return Auth::user();
|
||||
} else { // not logged in, get first user
|
||||
return User::first();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class SettingsController extends Controller
|
|||
public function edit($id)
|
||||
{
|
||||
$setting = Setting::find($id);
|
||||
//die("s: ".$setting->label);
|
||||
|
||||
if((bool)$setting->system === true) return abort(404);
|
||||
|
||||
|
@ -55,6 +56,7 @@ class SettingsController extends Controller
|
|||
public function update(Request $request, $id)
|
||||
{
|
||||
$setting = Setting::find($id);
|
||||
$user = $this->user();
|
||||
|
||||
if (!is_null($setting)) {
|
||||
$data = Setting::getInput();
|
||||
|
@ -64,17 +66,14 @@ class SettingsController extends Controller
|
|||
|
||||
if($request->hasFile('value')) {
|
||||
$path = $request->file('value')->store('backgrounds');
|
||||
$setting->value = $path;
|
||||
$setting_value = $path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
$setting->value = $data->value;
|
||||
$setting_value = $data->value;
|
||||
}
|
||||
|
||||
$setting->save();
|
||||
|
||||
$user->settings()->updateExistingPivot($setting->id, ['value' => $setting_value]);
|
||||
$route = route('settings.index', [], false);
|
||||
return redirect($route)
|
||||
->with([
|
||||
|
|
|
@ -37,7 +37,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
}
|
||||
|
||||
// check version to see if an upgrade is needed
|
||||
$db_version = Setting::fetch('version');
|
||||
$db_version = Setting::_fetch('version');
|
||||
$app_version = config('app.version');
|
||||
if(version_compare($app_version, $db_version) == 1) { // app is higher than db, so need to run migrations etc
|
||||
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace App;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Form;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
@ -46,6 +48,12 @@ class Setting extends Model
|
|||
|
||||
public function getListValueAttribute()
|
||||
{
|
||||
if((bool)$this->system === true) {
|
||||
$value = self::_fetch($this->key);
|
||||
} else {
|
||||
$value = self::fetch($this->key);
|
||||
}
|
||||
$this->value = $value;
|
||||
switch($this->type) {
|
||||
case 'image':
|
||||
if(!empty($this->value)) {
|
||||
|
@ -80,6 +88,8 @@ class Setting extends Model
|
|||
|
||||
public function getEditValueAttribute()
|
||||
{
|
||||
$user = $this->user();
|
||||
$this->value = $this->users()->where('id', $user->id)->first()->pivot->value;
|
||||
switch($this->type) {
|
||||
case 'image':
|
||||
$value = '';
|
||||
|
@ -125,6 +135,7 @@ class Setting extends Model
|
|||
return $this->belongsTo('App\SettingGroup', 'group_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
|
@ -132,14 +143,39 @@ class Setting extends Model
|
|||
*/
|
||||
public static function fetch($key)
|
||||
{
|
||||
if (Setting::cached($key)) {
|
||||
return Setting::$cache[$key];
|
||||
$user = self::user();
|
||||
return self::_fetch($key, $user);
|
||||
}
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function _fetch($key, $user=null)
|
||||
{
|
||||
$cachekey = ($user === null) ? $key : $key.'-'.$user->id;
|
||||
if (Setting::cached($cachekey)) {
|
||||
return Setting::$cache[$cachekey];
|
||||
} else {
|
||||
$find = self::where('key', '=', $key)->first();
|
||||
|
||||
if (!is_null($find)) {
|
||||
$value = $find->value;
|
||||
Setting::add($key, $value);
|
||||
if((bool)$find->system === true) { // if system variable use global value
|
||||
$value = $find->value;
|
||||
} else { // not system variable so use user specific value
|
||||
// check if user specified value has been set
|
||||
$usersetting = $user->settings->where('id', $find->id)->first();
|
||||
//die(print_r($usersetting));
|
||||
//->pivot->value;
|
||||
if(isset($usersetting) && !empty($usersetting)) {
|
||||
$value = $usersetting->pivot->value;
|
||||
} else { // if not get default from base setting
|
||||
$user->settings()->save($find, ['value' => $find->value]);
|
||||
$value = $find->value;
|
||||
}
|
||||
|
||||
}
|
||||
Setting::add($cachekey, $value);
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
|
@ -175,21 +211,23 @@ class Setting extends Model
|
|||
$output = '';
|
||||
$homepage_search = self::fetch('homepage_search');
|
||||
$search_provider = self::where('key', '=', 'search_provider')->first();
|
||||
|
||||
//die(var_dump($search_provider->value));
|
||||
$user_search_provider = self::fetch('search_provider');
|
||||
//die(print_r($search_provider));
|
||||
|
||||
//die(var_dump($user_search_provider));
|
||||
// return early if search isn't applicable
|
||||
if((bool)$homepage_search !== true) return $output;
|
||||
if($search_provider->value === 'none') return $output;
|
||||
if(empty($search_provider->value)) return $output;
|
||||
if(is_null($search_provider->value)) return $output;
|
||||
if($user_search_provider === 'none') return $output;
|
||||
if(empty($user_search_provider)) return $output;
|
||||
if(is_null($user_search_provider)) return $output;
|
||||
|
||||
|
||||
if((bool)$homepage_search && (bool)$search_provider) {
|
||||
|
||||
$options = (array)json_decode($search_provider->options);
|
||||
$name = $options[$search_provider->value];
|
||||
if((bool)$search_provider->value) {
|
||||
switch($search_provider->value) {
|
||||
$name = $options[$user_search_provider];
|
||||
if((bool)$user_search_provider) {
|
||||
switch($user_search_provider) {
|
||||
case 'google':
|
||||
$url = 'https://www.google.com/search';
|
||||
$var = 'q';
|
||||
|
@ -224,7 +262,17 @@ class Setting extends Model
|
|||
*/
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany('App\User');
|
||||
return $this->belongsToMany('App\User')->withPivot('value');
|
||||
}
|
||||
|
||||
public static function user()
|
||||
{
|
||||
if (Auth::check()) { // if logged in, set this user
|
||||
return Auth::user();
|
||||
} else { // not logged in, get first user
|
||||
return User::first();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class User extends Authenticatable
|
|||
*/
|
||||
public function settings()
|
||||
{
|
||||
return $this->belongsToMany('App\Setting');
|
||||
return $this->belongsToMany('App\Setting')->withPivot('value');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ return [
|
|||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Heimdall'),
|
||||
'version' => '1.4.14',
|
||||
'version' => '1.5.0',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
BIN
database/app.sqlite-journal
Normal file
BIN
database/app.sqlite-journal
Normal file
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
|
@ -71,9 +71,11 @@
|
|||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<a href="">Switch User</a>
|
||||
@yield('content')
|
||||
<div id="config-buttons">
|
||||
|
||||
|
||||
@if(Route::is('dash') || Route::is('tags.show'))
|
||||
<a id="config-button" class="config" href=""><i class="fas fa-exchange"></i></a>
|
||||
@endif
|
65
resources/views/layouts/users.blade.php
Normal file
65
resources/views/layouts/users.blade.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<!doctype html>
|
||||
<html lang="{{ app()->getLocale() }}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>{{ config('app.name') }}</title>
|
||||
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
|
||||
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
|
||||
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
|
||||
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
|
||||
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
|
||||
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<meta name="msapplication-TileColor" content="#ffffff">
|
||||
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<link rel="stylesheet" href="{{ asset('css/app.css') }}" type="text/css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"{!! $alt_bg !!}>
|
||||
<div class="content">
|
||||
<main>
|
||||
@if ($message = Session::get('success'))
|
||||
<div class="message-container">
|
||||
<div class="alert alert-success">
|
||||
<p>{{ $message }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if (count($errors) > 0)
|
||||
<div class="message-container">
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@yield('content')
|
||||
</main>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
<script>!window.jQuery && document.write('<script src="/js/jquery-3.3.1.min.js"><\/script>')</script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||
<script src="{{ asset('js/app.js?v=2') }}"></script>
|
||||
@yield('scripts')
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<section class="module-container">
|
||||
|
|
7
resources/views/userselect.blade.php
Normal file
7
resources/views/userselect.blade.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
@extends('layouts.users')
|
||||
|
||||
@section('content')
|
||||
|
||||
here
|
||||
|
||||
@endsection
|
|
@ -1,4 +1,4 @@
|
|||
@extends('app')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@include('partials.search')
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
|
||||
*/
|
||||
|
||||
Route::get('/userselect', 'Auth\LoginController@index')->name('user.select');
|
||||
|
||||
Route::get('/', 'ItemController@dash')->name('dash');
|
||||
|
||||
Route::resources([
|
||||
|
|
Loading…
Reference in a new issue