mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-13 17:14:10 -08:00
Fixes #1247 - allow SVG logo upload
This commit is contained in:
parent
55415e8f56
commit
fd805bde50
|
@ -3,6 +3,7 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Input;
|
use Input;
|
||||||
use Lang;
|
use Lang;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\Ldap;
|
use App\Models\Ldap;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
|
@ -18,6 +19,8 @@ use Mail;
|
||||||
use Auth;
|
use Auth;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Http\Requests\SetupUserRequest;
|
use App\Http\Requests\SetupUserRequest;
|
||||||
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller handles all actions related to Settings for
|
* This controller handles all actions related to Settings for
|
||||||
|
@ -292,7 +295,7 @@ class SettingsController extends Controller
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function postEdit()
|
public function postEdit(ImageUploadRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
|
@ -301,25 +304,10 @@ class SettingsController extends Controller
|
||||||
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
|
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get('clear_logo')=='1') {
|
|
||||||
$setting->logo = null;
|
|
||||||
} elseif (Input::file('logo_img')) {
|
|
||||||
if (!config('app.lock_passwords')) {
|
|
||||||
$image = Input::file('logo_img');
|
|
||||||
$file_name = "logo.".$image->getClientOriginalExtension();
|
|
||||||
$path = public_path('uploads/'.$file_name);
|
|
||||||
Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
$constraint->upsize();
|
|
||||||
})->save($path);
|
|
||||||
$setting->logo = $file_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!config('app.lock_passwords')) {
|
if (!config('app.lock_passwords')) {
|
||||||
$setting->site_name = e(Input::get('site_name'));
|
$setting->site_name = e(Input::get('site_name'));
|
||||||
$setting->brand = e(Input::get('brand'));
|
|
||||||
$setting->custom_css = e(Input::get('custom_css'));
|
$setting->custom_css = e(Input::get('custom_css'));
|
||||||
|
|
||||||
if (Input::get('two_factor_enabled')=='') {
|
if (Input::get('two_factor_enabled')=='') {
|
||||||
|
@ -420,6 +408,28 @@ class SettingsController extends Controller
|
||||||
$setting->ldap_tls = e(Input::get('ldap_tls', '0'));
|
$setting->ldap_tls = e(Input::get('ldap_tls', '0'));
|
||||||
$setting->ldap_pw_sync = e(Input::get('ldap_pw_sync', '0'));
|
$setting->ldap_pw_sync = e(Input::get('ldap_pw_sync', '0'));
|
||||||
|
|
||||||
|
|
||||||
|
if ($request->input('clear_logo')=='1') {
|
||||||
|
$setting->logo = null;
|
||||||
|
$setting->brand = 1;
|
||||||
|
} elseif ($request->hasFile('image')) {
|
||||||
|
|
||||||
|
if (!config('app.lock_passwords')) {
|
||||||
|
$image = $request->file('image');
|
||||||
|
$file_name = "logo.".$image->getClientOriginalExtension();
|
||||||
|
$path = public_path('uploads');
|
||||||
|
if ($image->getClientOriginalExtension()!='svg') {
|
||||||
|
Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
$constraint->upsize();
|
||||||
|
})->save($path.'/'.$file_name);
|
||||||
|
} else {
|
||||||
|
$image->move($path, $file_name);
|
||||||
|
}
|
||||||
|
$setting->logo = $file_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($setting->save()) {
|
if ($setting->save()) {
|
||||||
return redirect()->to("admin/settings/app")->with('success', trans('admin/settings/message.update.success'));
|
return redirect()->to("admin/settings/app")->with('success', trans('admin/settings/message.update.success'));
|
||||||
} else {
|
} else {
|
||||||
|
|
35
app/Http/Requests/ImageUploadRequest.php
Normal file
35
app/Http/Requests/ImageUploadRequest.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class ImageUploadRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'image' => 'mimes:png,gif,jpg,jpeg,svg|max:2000'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function response(array $errors)
|
||||||
|
{
|
||||||
|
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
|
||||||
|
}
|
||||||
|
}
|
|
@ -128,7 +128,7 @@
|
||||||
<!-- /.form-group -->
|
<!-- /.form-group -->
|
||||||
|
|
||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<div class="form-group {{ $errors->has('logo') ? 'has-error' : '' }}">
|
<div class="form-group {{ $errors->has('image') ? 'has-error' : '' }}">
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{{ Form::label('logo', trans('admin/settings/general.logo')) }}
|
{{ Form::label('logo', trans('admin/settings/general.logo')) }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -136,8 +136,8 @@
|
||||||
@if (config('app.lock_passwords'))
|
@if (config('app.lock_passwords'))
|
||||||
<p class="help-block">{{ trans('general.lock_passwords') }}</p>
|
<p class="help-block">{{ trans('general.lock_passwords') }}</p>
|
||||||
@else
|
@else
|
||||||
{{ Form::file('logo_img') }}
|
{{ Form::file('image') }}
|
||||||
{!! $errors->first('logo', '<span class="alert-msg">:message</span>') !!}
|
{!! $errors->first('image', '<span class="alert-msg">:message</span>') !!}
|
||||||
{{ Form::checkbox('clear_logo', '1', Input::old('clear_logo'),array('class' => 'minimal')) }} Remove
|
{{ Form::checkbox('clear_logo', '1', Input::old('clear_logo'),array('class' => 'minimal')) }} Remove
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue