Browse Source

Get settings working and autologin

pull/260/head
Kode 6 years ago
parent
commit
d0293c785b
  1. 5
      app/Http/Controllers/Auth/LoginController.php
  2. 5
      app/Http/Controllers/SettingsController.php
  3. 25
      app/Providers/AppServiceProvider.php
  4. 2
      database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php
  5. 4
      database/seeds/UsersSeeder.php
  6. 75
      public/css/app.css
  7. 2
      public/mix-manifest.json
  8. 54
      resources/assets/sass/_app.scss
  9. 56
      resources/views/auth/login.blade.php
  10. 2
      resources/views/layouts/app.blade.php
  11. 11
      resources/views/userselect.blade.php
  12. 4
      vendor/composer/ClassLoader.php
  13. 43
      vendor/composer/LICENSE
  14. 2
      vendor/composer/autoload_classmap.php
  15. 2
      vendor/composer/autoload_static.php

5
app/Http/Controllers/Auth/LoginController.php

@ -93,7 +93,10 @@ class LoginController extends Controller
public function autologin($uuid) public function autologin($uuid)
{ {
$user = User::where('autologin', $uuid)->first();
Auth::login($user);
session(['current_user' => $user]);
return redirect()->route('dash');
} }
/** /**

5
app/Http/Controllers/SettingsController.php

@ -103,10 +103,11 @@ class SettingsController extends Controller
*/ */
public function clear($id) public function clear($id)
{ {
$user = $this->user();
$setting = Setting::find($id); $setting = Setting::find($id);
if((bool)$setting->system !== true) { if((bool)$setting->system !== true) {
$setting->value = ''; $user->settings()->detach($setting->id);
$setting->save(); $user->settings()->save($setting, ['uservalue' => '']);
} }
$route = route('settings.index', [], false); $route = route('settings.index', [], false);
return redirect($route) return redirect($route)

25
app/Providers/AppServiceProvider.php

@ -7,7 +7,6 @@ use Artisan;
use Schema; use Schema;
use App\Setting; use App\Setting;
use App\User; use App\User;
use Session;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@ -18,7 +17,7 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
$alt_bg = '';
if(!is_file(base_path('.env'))) { if(!is_file(base_path('.env'))) {
touch(base_path('.env')); touch(base_path('.env'));
@ -34,11 +33,6 @@ class AppServiceProvider extends ServiceProvider
} }
if(is_file(database_path('app.sqlite'))) { if(is_file(database_path('app.sqlite'))) {
if(Schema::hasTable('settings')) { if(Schema::hasTable('settings')) {
die("s: ".\Session::get('current_user'));
//die("c: ".User::currentUser());
if($bg_image = Setting::_fetch('background_image', User::currentUser())) {
$alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"';
}
// check version to see if an upgrade is needed // check version to see if an upgrade is needed
$db_version = Setting::_fetch('version'); $db_version = Setting::_fetch('version');
@ -49,16 +43,25 @@ class AppServiceProvider extends ServiceProvider
} else { } else {
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true)); Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
} }
$lang = Setting::fetch('language');
\App::setLocale($lang);
} }
if(!is_file(public_path('storage'))) { if(!is_file(public_path('storage'))) {
Artisan::call('storage:link'); Artisan::call('storage:link');
} }
view()->share('alt_bg', $alt_bg);
//var_dump(env('FORCE_HTTPS')); // User specific settings need to go here as session isn't available at this point in the app
view()->composer('*', function ($view)
{
$alt_bg = '';
if($bg_image = Setting::fetch('background_image')) {
$alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"';
}
$lang = Setting::fetch('language');
\App::setLocale($lang);
$view->with('alt_bg', $alt_bg );
});
if (env('FORCE_HTTPS') === true) { if (env('FORCE_HTTPS') === true) {
\URL::forceScheme('https'); \URL::forceScheme('https');

2
database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php

@ -19,7 +19,7 @@ class CreateSettingUserPivotTable extends Migration
$table->integer('user_id')->unsigned()->index(); $table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['setting_id', 'user_id']); $table->primary(['setting_id', 'user_id']);
$table->string('value')->nullable(); $table->string('uservalue')->nullable();
}); });
} }

4
database/seeds/UsersSeeder.php

@ -16,8 +16,8 @@ class UsersSeeder extends Seeder
if(!$user = User::find(1)) { if(!$user = User::find(1)) {
$user = new User; $user = new User;
$user->id = 1; $user->id = 1;
$user->name = 'User'; $user->name = 'Admin';
$user->email = 'test@test.com'; $user->email = 'admin@test.com';
$user->save(); $user->save();
} else { } else {
//$user->save(); //$user->save();

75
public/css/app.css

@ -233,6 +233,17 @@ body {
background: #cfd2d4; background: #cfd2d4;
} }
#switchuser {
background: rgba(0, 0, 0, 0.6);
position: absolute;
padding: 5px;
color: white;
text-align: center;
top: 0;
left: 0;
right: 0;
}
#app { #app {
display: -webkit-box; display: -webkit-box;
display: -ms-flexbox; display: -ms-flexbox;
@ -323,7 +334,7 @@ body {
} }
#app main, #app #sortable { #app main, #app #sortable {
padding: 10px; padding: 30px 10px;
display: -webkit-box; display: -webkit-box;
display: -ms-flexbox; display: -ms-flexbox;
display: flex; display: flex;
@ -374,6 +385,68 @@ body {
margin-top: 12px; margin-top: 12px;
} }
.userlist {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.userlist .user {
background: rgba(0, 0, 0, 0.5);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
padding: 15px;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin: 20px;
color: white;
text-decoration: none;
border-radius: 15px;
border: 5px solid rgba(255, 255, 255, 0.7);
-webkit-box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.4);
box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.4);
}
.userlist .user-img {
width: 130px;
height: 130px;
margin-bottom: 20px;
border-radius: 50%;
margin: 10px 10px 15px;
}
.userlist #password {
color: #2f313a;
width: 100%;
padding: 5px 10px;
margin: 15px -5px;
}
.userlist .btn {
width: 100%;
}
.userlist .forgot {
color: white;
font-size: 12px;
margin-top: 25px;
}
.item-container { .item-container {
position: relative; position: relative;
} }

2
public/mix-manifest.json

@ -1,4 +1,4 @@
{ {
"/css/app.css": "/css/app.css?id=2aa9dedf14862069c2ff", "/css/app.css": "/css/app.css?id=6bc80b2f799b708a8024",
"/js/app.js": "/js/app.js?id=32cbf6f4924b46ae7e05" "/js/app.js": "/js/app.js?id=32cbf6f4924b46ae7e05"
} }

54
resources/assets/sass/_app.scss

@ -7,7 +7,16 @@ html {
body { body {
background: $body-bg; background: $body-bg;
} }
#switchuser {
background: rgba(0,0,0,0.6);
position: absolute;
padding: 5px;
color: white;
text-align: center;
top:0;
left: 0;
right: 0;
}
#app { #app {
display: flex; display: flex;
min-height: 100vh; min-height: 100vh;
@ -70,7 +79,7 @@ body {
flex-direction: column; flex-direction: column;
} }
main, #sortable { main, #sortable {
padding: 10px; padding: 30px 10px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -104,6 +113,47 @@ body {
} }
} }
.userlist {
display: flex;
justify-content: center;
align-items: center;
.user {
background: rgba(0,0,0,0.5);
display: flex;
padding: 15px;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 20px;
color: white;
text-decoration: none;
border-radius: 15px;
border: 5px solid rgba(255,255,255, 0.7);
box-shadow: 0 0 10px 0px rgba(0,0,0,0.4);
}
.user-img {
width: 130px;
height: 130px;
margin-bottom: 20px;
border-radius: 50%;
margin: 10px 10px 15px;
}
#password {
color: $app-text;
width: 100%;
padding: 5px 10px;
margin: 15px -5px;
}
.btn {
width: 100%;
}
.forgot {
color: white;
font-size: 12px;
margin-top: 25px;
}
}
.item-container { .item-container {
//width: 340px; //width: 340px;
//transition: width .35s ease-in-out; //transition: width .35s ease-in-out;

56
resources/views/auth/login.blade.php

@ -1,55 +1,25 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<div class="container"> <?php
<div class="row"> $user = \App\User::currentUser();
<div class="col-md-8 col-md-offset-2"> ?>
<div class="panel panel-default">
<div class="panel-heading">Login as {{ \App\User::currentUser()->name }}</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('login') }}"> <form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }} {{ csrf_field() }}
<div class="userlist">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <div class="user" href="{{ route('user.set', [$user->id]) }}">
<label for="password" class="col-md-4 control-label">Password</label> @if($user->avatar)
<img class="user-img" src="{{ asset('/storage/'.$user->avatar) }}" />
<div class="col-md-6"> @else
<input id="password" type="password" class="form-control" name="password" required> <img class="user-img" src="{{ asset('/img/heimdall-icon-small.png') }}" />
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif @endif
{{ $user->name }}
<input id="password" type="password" class="form-control" name="password" required>
<button type="submit" class="btn btn-primary">Login</button>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form> </form>
</div>
</div>
</div>
</div>
</div>
@endsection @endsection

2
resources/views/layouts/app.blade.php

@ -71,7 +71,7 @@
</div> </div>
</div> </div>
@endif @endif
<a style="background: rgba(0,0,0,0.6); position: absolute; padding: 5px; color: white; text-align: center; top:0; left: 0; right: 0;" href="{{ route('user.select') }}">Switch User</a> <a id="switchuser" href="{{ route('user.select') }}">Switch User</a>
@yield('content') @yield('content')
<div id="config-buttons"> <div id="config-buttons">

11
resources/views/userselect.blade.php

@ -2,8 +2,17 @@
@section('content') @section('content')
<div class="userlist">
@foreach($users as $user) @foreach($users as $user)
<a href="{{ route('user.set', [$user->id]) }}">{{ $user->name }}</a> <a class="user" href="{{ route('user.set', [$user->id]) }}">
@if($user->avatar)
<img class="user-img" src="{{ asset('/storage/'.$user->avatar) }}" />
@else
<img class="user-img" src="{{ asset('/img/heimdall-icon-small.png') }}" />
@endif
{{ $user->name }}
</a>
@endforeach @endforeach
</div>
@endsection @endsection

4
vendor/composer/ClassLoader.php

@ -379,9 +379,9 @@ class ClassLoader
$subPath = substr($subPath, 0, $lastPos); $subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\'; $search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) { if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) { foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) { $length = $this->prefixLengthsPsr4[$first][$search];
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file; return $file;
} }
} }

43
vendor/composer/LICENSE

@ -1,52 +1,16 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Composer
Upstream-Contact: Jordi Boggiano <j.boggiano@seld.be>
Source: https://github.com/composer/composer
Files: * Copyright (c) Nils Adermann, Jordi Boggiano
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
License: Expat
Files: src/Composer/Util/TlsHelper.php
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
2013, Evan Coury <me@evancoury.com>
License: Expat and BSD-2-Clause
License: BSD-2-Clause
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: Expat
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions: to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -54,3 +18,4 @@ License: Expat
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.

2
vendor/composer/autoload_classmap.php

@ -19,6 +19,7 @@ return array(
'App\\Http\\Controllers\\TagController' => $baseDir . '/app/Http/Controllers/TagController.php', 'App\\Http\\Controllers\\TagController' => $baseDir . '/app/Http/Controllers/TagController.php',
'App\\Http\\Controllers\\UserController' => $baseDir . '/app/Http/Controllers/UserController.php', 'App\\Http\\Controllers\\UserController' => $baseDir . '/app/Http/Controllers/UserController.php',
'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\CheckAllowed' => $baseDir . '/app/Http/Middleware/CheckAllowed.php',
'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php',
'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.php', 'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.php',
'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php',
@ -32,6 +33,7 @@ return array(
'App\\Providers\\RouteServiceProvider' => $baseDir . '/app/Providers/RouteServiceProvider.php', 'App\\Providers\\RouteServiceProvider' => $baseDir . '/app/Providers/RouteServiceProvider.php',
'App\\Setting' => $baseDir . '/app/Setting.php', 'App\\Setting' => $baseDir . '/app/Setting.php',
'App\\SettingGroup' => $baseDir . '/app/SettingGroup.php', 'App\\SettingGroup' => $baseDir . '/app/SettingGroup.php',
'App\\SettingUser' => $baseDir . '/app/SettingUser.php',
'App\\SupportedApps\\AirSonic' => $baseDir . '/app/SupportedApps/AirSonic.php', 'App\\SupportedApps\\AirSonic' => $baseDir . '/app/SupportedApps/AirSonic.php',
'App\\SupportedApps\\Bazarr' => $baseDir . '/app/SupportedApps/Bazarr.php', 'App\\SupportedApps\\Bazarr' => $baseDir . '/app/SupportedApps/Bazarr.php',
'App\\SupportedApps\\BookStack' => $baseDir . '/app/SupportedApps/BookStack.php', 'App\\SupportedApps\\BookStack' => $baseDir . '/app/SupportedApps/BookStack.php',

2
vendor/composer/autoload_static.php

@ -372,6 +372,7 @@ class ComposerStaticInit4b6fb9210a1ea37c2db27b8ff53a1ecf
'App\\Http\\Controllers\\TagController' => __DIR__ . '/../..' . '/app/Http/Controllers/TagController.php', 'App\\Http\\Controllers\\TagController' => __DIR__ . '/../..' . '/app/Http/Controllers/TagController.php',
'App\\Http\\Controllers\\UserController' => __DIR__ . '/../..' . '/app/Http/Controllers/UserController.php', 'App\\Http\\Controllers\\UserController' => __DIR__ . '/../..' . '/app/Http/Controllers/UserController.php',
'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\CheckAllowed' => __DIR__ . '/../..' . '/app/Http/Middleware/CheckAllowed.php',
'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php',
'App\\Http\\Middleware\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.php', 'App\\Http\\Middleware\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.php',
'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php',
@ -385,6 +386,7 @@ class ComposerStaticInit4b6fb9210a1ea37c2db27b8ff53a1ecf
'App\\Providers\\RouteServiceProvider' => __DIR__ . '/../..' . '/app/Providers/RouteServiceProvider.php', 'App\\Providers\\RouteServiceProvider' => __DIR__ . '/../..' . '/app/Providers/RouteServiceProvider.php',
'App\\Setting' => __DIR__ . '/../..' . '/app/Setting.php', 'App\\Setting' => __DIR__ . '/../..' . '/app/Setting.php',
'App\\SettingGroup' => __DIR__ . '/../..' . '/app/SettingGroup.php', 'App\\SettingGroup' => __DIR__ . '/../..' . '/app/SettingGroup.php',
'App\\SettingUser' => __DIR__ . '/../..' . '/app/SettingUser.php',
'App\\SupportedApps\\AirSonic' => __DIR__ . '/../..' . '/app/SupportedApps/AirSonic.php', 'App\\SupportedApps\\AirSonic' => __DIR__ . '/../..' . '/app/SupportedApps/AirSonic.php',
'App\\SupportedApps\\Bazarr' => __DIR__ . '/../..' . '/app/SupportedApps/Bazarr.php', 'App\\SupportedApps\\Bazarr' => __DIR__ . '/../..' . '/app/SupportedApps/Bazarr.php',
'App\\SupportedApps\\BookStack' => __DIR__ . '/../..' . '/app/SupportedApps/BookStack.php', 'App\\SupportedApps\\BookStack' => __DIR__ . '/../..' . '/app/SupportedApps/BookStack.php',

Loading…
Cancel
Save