Get settings working and autologin

This commit is contained in:
Kode 2018-10-15 19:56:45 +01:00
parent aa351e31bf
commit d0293c785b
15 changed files with 204 additions and 126 deletions

View file

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

View file

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

View file

@ -7,7 +7,6 @@ use Artisan;
use Schema;
use App\Setting;
use App\User;
use Session;
class AppServiceProvider extends ServiceProvider
{
@ -18,7 +17,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
$alt_bg = '';
if(!is_file(base_path('.env'))) {
touch(base_path('.env'));
@ -34,11 +33,6 @@ class AppServiceProvider extends ServiceProvider
}
if(is_file(database_path('app.sqlite'))) {
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
$db_version = Setting::_fetch('version');
@ -49,16 +43,25 @@ class AppServiceProvider extends ServiceProvider
} else {
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
}
$lang = Setting::fetch('language');
\App::setLocale($lang);
}
if(!is_file(public_path('storage'))) {
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) {
\URL::forceScheme('https');

View file

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

View file

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

75
public/css/app.css vendored
View file

@ -233,6 +233,17 @@ body {
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 {
display: -webkit-box;
display: -ms-flexbox;
@ -323,7 +334,7 @@ body {
}
#app main, #app #sortable {
padding: 10px;
padding: 30px 10px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
@ -374,6 +385,68 @@ body {
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 {
position: relative;
}

View file

@ -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"
}

View file

@ -7,7 +7,16 @@ html {
body {
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 {
display: flex;
min-height: 100vh;
@ -70,7 +79,7 @@ body {
flex-direction: column;
}
main, #sortable {
padding: 10px;
padding: 30px 10px;
display: flex;
justify-content: 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 {
//width: 340px;
//transition: width .35s ease-in-out;

View file

@ -1,55 +1,25 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<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') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</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>
</div>
</div>
<?php
$user = \App\User::currentUser();
?>
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="userlist">
<div 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 }}
<input id="password" type="password" class="form-control" name="password" required>
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</div>
</form>
@endsection

View file

@ -71,7 +71,7 @@
</div>
</div>
@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')
<div id="config-buttons">

View file

@ -2,8 +2,17 @@
@section('content')
<div class="userlist">
@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
</div>
@endsection

View file

@ -379,9 +379,9 @@ class ClassLoader
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
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;
}
}

View file

@ -1,56 +1,21 @@
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: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
License: Expat
Copyright (c) Nils Adermann, Jordi Boggiano
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
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
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
to do so, subject to the following conditions:
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.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
THE SOFTWARE.
License: Expat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
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
to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
THE SOFTWARE.

View file

@ -19,6 +19,7 @@ return array(
'App\\Http\\Controllers\\TagController' => $baseDir . '/app/Http/Controllers/TagController.php',
'App\\Http\\Controllers\\UserController' => $baseDir . '/app/Http/Controllers/UserController.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\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.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\\Setting' => $baseDir . '/app/Setting.php',
'App\\SettingGroup' => $baseDir . '/app/SettingGroup.php',
'App\\SettingUser' => $baseDir . '/app/SettingUser.php',
'App\\SupportedApps\\AirSonic' => $baseDir . '/app/SupportedApps/AirSonic.php',
'App\\SupportedApps\\Bazarr' => $baseDir . '/app/SupportedApps/Bazarr.php',
'App\\SupportedApps\\BookStack' => $baseDir . '/app/SupportedApps/BookStack.php',

View file

@ -372,6 +372,7 @@ class ComposerStaticInit4b6fb9210a1ea37c2db27b8ff53a1ecf
'App\\Http\\Controllers\\TagController' => __DIR__ . '/../..' . '/app/Http/Controllers/TagController.php',
'App\\Http\\Controllers\\UserController' => __DIR__ . '/../..' . '/app/Http/Controllers/UserController.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\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.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\\Setting' => __DIR__ . '/../..' . '/app/Setting.php',
'App\\SettingGroup' => __DIR__ . '/../..' . '/app/SettingGroup.php',
'App\\SettingUser' => __DIR__ . '/../..' . '/app/SettingUser.php',
'App\\SupportedApps\\AirSonic' => __DIR__ . '/../..' . '/app/SupportedApps/AirSonic.php',
'App\\SupportedApps\\Bazarr' => __DIR__ . '/../..' . '/app/SupportedApps/Bazarr.php',
'App\\SupportedApps\\BookStack' => __DIR__ . '/../..' . '/app/SupportedApps/BookStack.php',